1. Divide the number repeatedly by 2:
Keep track of each remainder.
We stop when we get a quotient that is equal to zero.
- division = quotient + remainder;
- 172 301 378 ÷ 2 = 86 150 689 + 0;
- 86 150 689 ÷ 2 = 43 075 344 + 1;
- 43 075 344 ÷ 2 = 21 537 672 + 0;
- 21 537 672 ÷ 2 = 10 768 836 + 0;
- 10 768 836 ÷ 2 = 5 384 418 + 0;
- 5 384 418 ÷ 2 = 2 692 209 + 0;
- 2 692 209 ÷ 2 = 1 346 104 + 1;
- 1 346 104 ÷ 2 = 673 052 + 0;
- 673 052 ÷ 2 = 336 526 + 0;
- 336 526 ÷ 2 = 168 263 + 0;
- 168 263 ÷ 2 = 84 131 + 1;
- 84 131 ÷ 2 = 42 065 + 1;
- 42 065 ÷ 2 = 21 032 + 1;
- 21 032 ÷ 2 = 10 516 + 0;
- 10 516 ÷ 2 = 5 258 + 0;
- 5 258 ÷ 2 = 2 629 + 0;
- 2 629 ÷ 2 = 1 314 + 1;
- 1 314 ÷ 2 = 657 + 0;
- 657 ÷ 2 = 328 + 1;
- 328 ÷ 2 = 164 + 0;
- 164 ÷ 2 = 82 + 0;
- 82 ÷ 2 = 41 + 0;
- 41 ÷ 2 = 20 + 1;
- 20 ÷ 2 = 10 + 0;
- 10 ÷ 2 = 5 + 0;
- 5 ÷ 2 = 2 + 1;
- 2 ÷ 2 = 1 + 0;
- 1 ÷ 2 = 0 + 1;
2. Construct the base 2 representation of the positive number:
Take all the remainders starting from the bottom of the list constructed above.
172 301 378(10) = 1010 0100 0101 0001 1100 0100 0010(2)
3. Determine the signed binary number bit length:
The base 2 number's actual length, in bits: 28.
- A signed binary's bit length must be equal to a power of 2, as of:
- 21 = 2; 22 = 4; 23 = 8; 24 = 16; 25 = 32; 26 = 64; ...
- The first bit (the leftmost) indicates the sign:
- 0 = positive integer number, 1 = negative integer number
The least number that is:
1) a power of 2
2) and is larger than the actual length, 28,
3) so that the first bit (leftmost) could be zero
(we deal with a positive number at this moment)
=== is: 32.
4. Get the positive binary computer representation on 32 bits (4 Bytes):
If needed, add extra 0s in front (to the left) of the base 2 number, up to the required length, 32.
Decimal Number 172 301 378(10) converted to signed binary in two's complement representation:
Spaces were used to group digits: for binary, by 4, for decimal, by 3.