4 ms·
One way to look at it is that the highest bit is negative instead of positive. So in an unsigned 8-bit integer, the highest bit is worth 128. In a signed intege
by LinAGKar 3y ago
One way to look at it is that the highest bit is negative instead of positive. So in an unsigned 8-bit integer, the highest bit is worth 128. In a signed integer, it's worth -128.
- jdthedisciple 3y agoThat is a brilliant way to look at it. So it's all the same for bits [0-6], except for a -128 offset. Awesome!
- andrepd 3y agoThis is precisely what made me "get" it
- mananaysiempre 3y agoFWIW, if you slog through it, you’ll find the C standard describes it in exactly that way :) E.g. in the latest public draft[1] 6.2.6.2p2: > If the sign bit is zero, it shall not affect the resulting value. If the sign bit is one, it has value −(2^{N−1}). [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf