how to represent out of range number in binary?
In 2 complements I read from wikipedia, the range is from -128 to 127. So I wonder how do we repres开发者_如何转开发ent 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
You can't, if you've only got 8 bits to work with. Unless you're willing to treat treat1000 0000
as both −128 and +128.
精彩评论