64 bit C question
mike ledoux
mwl+gnhlug at alumni.unh.edu
Tue Feb 17 17:54:30 EST 2009
On Tue, Feb 17, 2009 at 05:30:00PM -0500, bruce.labitt at autoliv.com wrote:
> Is there some way to to compile a C or C++ program that will output a
> 64bit hex value correctly? This is what I have so far...
[...]
> printf("long int N = %16x\n", N); // x800000000 correct
> printf("long long NN = %16x\n", NN); // prints 0 which is incorrect
> printf("long long NN = %li\n", NN); // prints 4294976296, which is
[...]
> Any suggestion to fix this? The compile command I am using is really
Try:
printf("long long NN = %16llx\n", NN);
For longs, long longs, etc. you should specify the correct length
modifier to printf, so the three lines quoted above should be
written as:
printf("long int N = %16xx\n", N);
printf("long long NN = %16llx\n", NN);
printf("long long NN = %lli\n", NN);
--
mwl+gnhlug at alumni.unh.edu OpenPGP KeyID 0x57C3430B
Holder of Past Knowledge CS, O-
"We can easily forgive a child who is afraid of the dark.
The real tragedy of life is when men are afraid of the light." Plato
More information about the gnhlug-discuss
mailing list