Setting all bits in int64_t

From the following code, I expect to set all bits to x in 1, but only the first 32 bits are set in one way or another:

int64_t x = 0xFFFFFFFF; x<<32; x|=0xFFFFFFFF; 

Note: printing x after each line results in 4294967295 (32 LSBs set to 1). Also, tried using numeric_limits<int64_t>::min() without success. My question is how to set all bits to x? Using RHEL5.5.

thanks

+4
source share
3 answers

x<<32 calculates the result of shifting x left by 32 bits and does nothing with the value. Instead, you want to use x <<= 32 .

+13
source

Why not int64_t x = -1 ? or uint64_t x = ~0 ?

+10
source

This will work:

 int64_t x = ~0LL; (iner 

or

 int64_t x = -1LL; 

You can get away with the lack of LL , but not guaranteed - it depends on the compiler.

+4
source

Source: https://habr.com/ru/post/1478884/


All Articles