Define a 64 bit integer in Linux

I am trying to define an integer with a width of 64 bits using the C language on Ubnutu 9.10. 9223372036854775808 is 2 ^ 23

long long max=9223372036854775808 long max=9223372036854775808 

When I compile it, the compiler issued a warning message:

 binary.c:79:19: warning: integer constant is so large that it is unsigned binary.c: In function 'bitReversal': binary.c:79: warning: this decimal constant is unsigned only in ISO C90 binary.c:79: warning: integer constant is too large for 'long' type 

Is the width of the 64-bit format long?

Regards,

+2
c
Feb 27
source share
4 answers
  long long max=9223372036854775808LL; // Note the LL // long max=9223372036854775808L; // Note the L 



A long long type is at least 64 bits, long type is at least 32 bits. Actual width depends on compiler platform and targeting.

Use int64_t and int32_t to provide a 64- / 32-bit integer in the variable.

+11
Feb 27
source share

The problem you are facing is that the number you are using (9223372036854775808) is 2**63 and the maximum value that your long long can hold (as a 64-bit signed add-on type 2s) is less this is 2**63 - 1 , or 9223372036854775807 (these are 63 binary 1 lines per line).

Constants that are too large for long long (as in this case) are set to unsigned long long , so you get a warning integer constant is so large that it is unsigned .

The long type is at least 32 bits, and the long long is at least 64 bits (both include the signed bit).

+5
Feb 28 '10 at 11:44
source share

I am not sure if this will fix your problem (LL solution looks good). But here is the recommendation:

You must use hexadecimal notation to write the maximum value of something.

 unsigned char max = 0xFF; unsigned short max = 0xFFFF; uint32_t max = 0xFFFFFFFF; uint64_t max = 0xFFFFFFFFFFFFFFFF; 

As you can see, this is readable.

To display the value:

printf("%lld\n", value_of_64b_int);

0
Feb 27 2018-10-28
source share

I think it depends on which platform you use. If you need to know exactly what type of integer type you are using, you should use the types from Stdint.h if you have this include file on your system.

0
Feb 27 2018-10-28
source share



All Articles