T
Tomás
What's the best portable way to set the MSB of an unsigned integer type?
Is the following any good?:
Start of with: 0000 0000
Flip all the bits: 1111 1111
Shift once to the right: 0111 1111
Flip all the bits: 1000 0000
Here it is done in code:
typedef unsigned short UIntType;
UIntType msb_only =
~( ~( (UIntType)0 ) >> 1 );
Is there a better way?
-Tomás
Is the following any good?:
Start of with: 0000 0000
Flip all the bits: 1111 1111
Shift once to the right: 0111 1111
Flip all the bits: 1000 0000
Here it is done in code:
typedef unsigned short UIntType;
UIntType msb_only =
~( ~( (UIntType)0 ) >> 1 );
Is there a better way?
-Tomás