In 2 complements I read from wikipedia, the range is from -128 to 127. So I wonder how do we represent 128 in 2 complement as it is out of range above?
You use more bits.
The range -128 to +127 is 256 unique values, which is 8 bits. If you need a larger range, you need more bits.
There is nothing restricting 2s-complement numbers to 8-bit values. For instance, a 16-bit 2s-complement number ranges from -32768 to +32767.
8-bit gives you the range: [-2^7 , 2^7-1] = [-128,127]
In general, 2's complement using n-bit can represent numbers in the range:
-2^(n-1) to +2^(n-1)-1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With