What are the required steps to convert base 10 integer
number 5 385 877 162 to signed binary code (in base 2)?
- A signed integer, written in base ten, or a decimal system number, is a number written using the digits 0 through 9 and the sign, which can be positive (+) or negative (-). If positive, the sign is usually not written. A number written in base two, or binary, is a number written using only the digits 0 and 1.
1. Divide the number repeatedly by 2:
Keep track of each remainder.
Stop when you get a quotient that is equal to zero.
- division = quotient + remainder;
- 5 385 877 162 ÷ 2 = 2 692 938 581 + 0;
- 2 692 938 581 ÷ 2 = 1 346 469 290 + 1;
- 1 346 469 290 ÷ 2 = 673 234 645 + 0;
- 673 234 645 ÷ 2 = 336 617 322 + 1;
- 336 617 322 ÷ 2 = 168 308 661 + 0;
- 168 308 661 ÷ 2 = 84 154 330 + 1;
- 84 154 330 ÷ 2 = 42 077 165 + 0;
- 42 077 165 ÷ 2 = 21 038 582 + 1;
- 21 038 582 ÷ 2 = 10 519 291 + 0;
- 10 519 291 ÷ 2 = 5 259 645 + 1;
- 5 259 645 ÷ 2 = 2 629 822 + 1;
- 2 629 822 ÷ 2 = 1 314 911 + 0;
- 1 314 911 ÷ 2 = 657 455 + 1;
- 657 455 ÷ 2 = 328 727 + 1;
- 328 727 ÷ 2 = 164 363 + 1;
- 164 363 ÷ 2 = 82 181 + 1;
- 82 181 ÷ 2 = 41 090 + 1;
- 41 090 ÷ 2 = 20 545 + 0;
- 20 545 ÷ 2 = 10 272 + 1;
- 10 272 ÷ 2 = 5 136 + 0;
- 5 136 ÷ 2 = 2 568 + 0;
- 2 568 ÷ 2 = 1 284 + 0;
- 1 284 ÷ 2 = 642 + 0;
- 642 ÷ 2 = 321 + 0;
- 321 ÷ 2 = 160 + 1;
- 160 ÷ 2 = 80 + 0;
- 80 ÷ 2 = 40 + 0;
- 40 ÷ 2 = 20 + 0;
- 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.
5 385 877 162(10) = 1 0100 0001 0000 0101 1111 0110 1010 1010(2)
3. Determine the signed binary number bit length:
The base 2 number's actual length, in bits: 33.
- 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) is reserved for 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, 33,
3) so that the first bit (leftmost) could be zero
(we deal with a positive number at this moment)
=== is: 64.
4. Get the positive binary computer representation on 64 bits (8 Bytes):
If needed, add extra 0s in front (to the left) of the base 2 number, up to the required length, 64:
5 385 877 162(10) Base 10 integer number converted and written as a signed binary code (in base 2):
5 385 877 162(10) = 0000 0000 0000 0000 0000 0000 0000 0001 0100 0001 0000 0101 1111 0110 1010 1010
Spaces were used to group digits: for binary, by 4, for decimal, by 3.