I use bit operations for options in the GUI, it became necessary to check whether at least 1 bit was set. Do I understand correctly that if the number is 0, then all the bits are in the reset state? It is not clear how to deal with the last bit that answers a positive number or a negative one. Used unsigned int. You can cycle through all the bits, but maybe this is not necessary and it is enough to simply compare with 0? Can there be a situation that there will be -0 and +0 bits set but still this is zero.

  • one
    If unsigned int then by definition there is no sign bit in it, so you can safely compare the value with zero. - zed
  • one
    A signed int also cannot have a negative zero. This is only in real numbers: double / float - maybe -0 . - Alexander Petrov

1 answer 1

The fact is that for integers, not just the bit responsible for the character (as in floating-point numbers for example) is usually used, but the special representation is an additional code that does not create a situation with a negative zero. In such a notation, for example, setting the top bit in byte 10000000 gives the number -128 , not -0 .