Archived

This topic is now archived and is closed to further replies.

vaneger

file i/o of a unsigned 64 or 128 bit interger

Recommended Posts

how do i convert those larger integers to a format that will allow me to output them? i cant seem to find it in msdn for some reason. also what are the max values for those?

Share this post


Link to post
Share on other sites
Exactly what types are you using?

The maximum number of discreet values = 2^n-1 where n is the number of bits and 2^n is 2 raised to the nth power. The largest value will depend on whether the number is signed or not. In the case of unsigned int's it's 18446744073709551615 and 3.4028236692093846346337460743177e+38.

[edited by - Solo on March 17, 2004 11:51:47 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Solo
Exactly what types are you using?

The maximum number of discreet values = 2^n-1


No. The max number of descreet values = 2^n, however this includes the integer value of 0, so the maximum unsigned number is 2^n-1

[edited by - Doc on March 17, 2004 12:10:08 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Doc

No. The max number of descreet values = 2^n, however this includes the integer value of 0, so the maximum unsigned number is 2^n-1



Oops.

Share this post


Link to post
Share on other sites
OP: So what types (__int64 or something?) and what IO functions (fwrite/iostreams?) are you using? Chances are you can just give the functions the address of the variable and tell them to write 8 or 16 bytes (depending on the type). Exactly how to do that depends on the types and the functions.

Share this post


Link to post
Share on other sites
well im currently using unsigned __int64 but if the code works for unsigned __int128 ill end up using that. for output im using fstream (ofstream, ifstream) how do i make those output a variable of that type cus when i go

ofstream fout;
fout.open("etc",etc);
fout<<some unsigned __int64<<endl;

it says fout operator ambigous :-\

Share this post


Link to post
Share on other sites
unsigned short is 16 bits, 0 to 65535. unsigned int is 32 bits, 0 to 4294967295. Ints take 4 bytes (on 32 bit/modern windows systems).

Share this post


Link to post
Share on other sites
I used __int64 with ofstream just fine:


ofstream fout;
fout.open("test.txt");
unsigned __int64 i = 5;
fout << i << endl;


This compiles normally for me with Visual Studio .NET 2003.

Also, you can find the max for any type with std::numeric_limits:


unsigned __int64 n = std::numeric_limits<unsigned __int64>::max();



[edited by - fizban75 on March 19, 2004 9:50:06 PM]

Share this post


Link to post
Share on other sites