How to represent a number from a range in binary format?

The 2 add-ons that I read from Wikipedia range from -128 to 127. So I wonder how we present 128 in 2 add-ons, since it goes beyond the above?

+3
source share
3 answers

You use more bits.

The range from -128 to +127 is 256 unique values, which is 8 bits. If you need a larger range, you need more bits.

There is nothing limiting to 2s padding numbers for 8-bit values. For example, a 16-bit number with the number 2s ranges from -32768 to +32767.

+6
source

8-bit gives you a range: [-2^7 , 2^7-1] = [-128,127]

, 2 n- :

-2^(n-1) to +2^(n-1)-1
+1

You cannot if you only have 8 bits to work with. If you do not want to treat treatment 1000 0000like & minus 128 and +128.

-1
source

Source: https://habr.com/ru/post/1721752/


All Articles