Pregunta

From following code I expect to set all bits in x to 1, but somehow only first 32 bits are set:

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

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

Thx

¿Fue útil?

Solución

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

Otros consejos

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

This will work:

int64_t x = ~0LL;   (iner

or

int64_t x = -1LL;

You may get away with not having the LL, but not guaranteed - depends on the compiler.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top