What are the required steps to convert base 10 integer
number -123 458 691 048 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. Start with the positive version of the number:
|-123 458 691 048| = 123 458 691 048
2. 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;
- 123 458 691 048 ÷ 2 = 61 729 345 524 + 0;
- 61 729 345 524 ÷ 2 = 30 864 672 762 + 0;
- 30 864 672 762 ÷ 2 = 15 432 336 381 + 0;
- 15 432 336 381 ÷ 2 = 7 716 168 190 + 1;
- 7 716 168 190 ÷ 2 = 3 858 084 095 + 0;
- 3 858 084 095 ÷ 2 = 1 929 042 047 + 1;
- 1 929 042 047 ÷ 2 = 964 521 023 + 1;
- 964 521 023 ÷ 2 = 482 260 511 + 1;
- 482 260 511 ÷ 2 = 241 130 255 + 1;
- 241 130 255 ÷ 2 = 120 565 127 + 1;
- 120 565 127 ÷ 2 = 60 282 563 + 1;
- 60 282 563 ÷ 2 = 30 141 281 + 1;
- 30 141 281 ÷ 2 = 15 070 640 + 1;
- 15 070 640 ÷ 2 = 7 535 320 + 0;
- 7 535 320 ÷ 2 = 3 767 660 + 0;
- 3 767 660 ÷ 2 = 1 883 830 + 0;
- 1 883 830 ÷ 2 = 941 915 + 0;
- 941 915 ÷ 2 = 470 957 + 1;
- 470 957 ÷ 2 = 235 478 + 1;
- 235 478 ÷ 2 = 117 739 + 0;
- 117 739 ÷ 2 = 58 869 + 1;
- 58 869 ÷ 2 = 29 434 + 1;
- 29 434 ÷ 2 = 14 717 + 0;
- 14 717 ÷ 2 = 7 358 + 1;
- 7 358 ÷ 2 = 3 679 + 0;
- 3 679 ÷ 2 = 1 839 + 1;
- 1 839 ÷ 2 = 919 + 1;
- 919 ÷ 2 = 459 + 1;
- 459 ÷ 2 = 229 + 1;
- 229 ÷ 2 = 114 + 1;
- 114 ÷ 2 = 57 + 0;
- 57 ÷ 2 = 28 + 1;
- 28 ÷ 2 = 14 + 0;
- 14 ÷ 2 = 7 + 0;
- 7 ÷ 2 = 3 + 1;
- 3 ÷ 2 = 1 + 1;
- 1 ÷ 2 = 0 + 1;
3. Construct the base 2 representation of the positive number:
Take all the remainders starting from the bottom of the list constructed above.
123 458 691 048(10) = 1 1100 1011 1110 1011 0110 0001 1111 1110 1000(2)
4. Determine the signed binary number bit length:
The base 2 number's actual length, in bits: 37.
- 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, 37,
3) so that the first bit (leftmost) could be zero
(we deal with a positive number at this moment)
=== is: 64.
5. 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:
123 458 691 048(10) = 0000 0000 0000 0000 0000 0000 0001 1100 1011 1110 1011 0110 0001 1111 1110 1000
6. Get the negative integer number representation:
To get the negative integer number representation on 64 bits (8 Bytes),
... change the first bit (the leftmost), from 0 to 1...
-123 458 691 048(10) Base 10 integer number converted and written as a signed binary code (in base 2):
-123 458 691 048(10) = 1000 0000 0000 0000 0000 0000 0001 1100 1011 1110 1011 0110 0001 1111 1110 1000
Spaces were used to group digits: for binary, by 4, for decimal, by 3.