64 bit C question

bruce.labitt at autoliv.com bruce.labitt at autoliv.com
Tue Feb 17 17:43:33 EST 2009


Nuts.  (Embarassed) Please disregard.  Real simple.. Use format code 
%16lx, rather than %16x.

gnhlug-discuss-bounces at mail.gnhlug.org wrote on 02/17/2009 05:30:00 PM:

> 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...
> 
> #include<cmath>
> int main()
> {
>   long int N;
>   long long NN;
> 
>   N  = (long int)  pow(2.0, 31.0);              // 2**31 = 
> 2*1024*1024*1024 = 2G
>   NN = (long long) pow(2.0, 32.0);              // 2**32 = 4G == dreaded 

> 32 bit boundary
> 
>   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 
> correct 
> 
> }
> 
> I need to write a hex string to file so my python program on a different 

> node can read it.
> I use fprintf, but am apparently getting the same results...
> 
> Any suggestion to fix this?  The compile command I am using is really 
> simple:
> 
> g++ -m64 -D_FILE_OFFSET_BITS=64 -I/usr/local/include -L/usr/local/lib 
> -omytestfile mytestfile.cpp
> 
> This program is on a 64 bit YDL system.  It is probably a classic - but 
I 
> am not sure how to proceed from here...
> 
> TIA,
> -Bruce
> 
> 
> 
> ******************************
> Neither the footer nor anything else in this E-mail is intended to 
> or constitutes an <br>electronic signature and/or legally binding 
> agreement in the absence of an <br>express statement or Autoliv 
> policy and/or procedure to the contrary.<br>This E-mail and any 
> attachments hereto are Autoliv property and may contain legally 
> <br>privileged, confidential and/or proprietary information.<br>The 
> recipient of this E-mail is prohibited from distributing, copying, 
> forwarding or in any way <br>disseminating any material contained 
> within this E-mail without prior written <br>permission from the 
> author. If you receive this E-mail in error, please <br>immediately 
> notify the author and delete this E-mail.  Autoliv disclaims all 
> <br>responsibility and liability for the consequences of any person 
> who fails to <br>abide by the terms herein. <br>
> ******************************
> 
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail.  Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************



More information about the gnhlug-discuss mailing list