Convert decimal numbers to binary numbers

What is the -10 binary form? How is it calculated?

+3
source share
4 answers

To convert -10 (decimal) to binary:

Repeat the absolute value (| -10 | = 10) of the number by 2 until you get 0 in quotient:

(10 / 2 = 5 R 0)
(5  / 2 = 2 R 1)
(2  / 2 = 1 R 0)
(1  / 2 = 0 R 1) // zero is the value in the quotient so we stop dividing

Put the leftovers to get the binary equivalent:

1010

For an 8-bit cell, the answer is 0000 1010, a 16-bit cell is 0000 0000 0000 1010, etc.

Take one padding by inverting the bits (we will assume that the 8-bit cell contains the final value):

0000 1010
1111 0101 // bits are inverted

Now take 2 add-ons, adding 1:

 1111 0101
+        1
----------
 1111 0110 // final answer

What happens to a 4-bit cell?

The only addition:

1010
0101 // inverted bits

Taking the second supplement causes:

 0101
+   1
 ----
 0110 // final answer for a 4-bit cell   

, , ( 0, 1) .

+7

10, .

10       0000 1010
invert   1111 0101
add 1    1111 0110
+4

. , -n, two complement of n.

+1

"" . -, , . , , - - ? , .

, 5- .

+10: 0 1 0 1 0

. ( 5) 1, , 0 . ( ) .

, :

-10: 1 1 0 1 0 (sign-magnitude, 5 bits)

. 1 0 (, - 1 s).

, :

-10: 1 0 1 0 1 (ones' complement, 5 bits)

, . , 1.

, :

-10: 1 0 1 0 1
             1
     ---------
     1 0 1 1 0 (two complement, 5 bits)
     ---------

, .

In addition, you might notice the position of the apostrophe in your additions and two additions. Why is this not a supplement or supplement? Then answer, from Knut:

The number of two additions is supplemented by one degree 2, and the number of additions is supplemented by a long sequence of 1s. In fact, there is also a “double complement” that has a radius of 3 and a complement with respect to (2 ... 22) 3

+1
source

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


All Articles