What are the required steps to convert base 10 integer
number -9 123 123 123 000 000 314 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:
|-9 123 123 123 000 000 314| = 9 123 123 123 000 000 314
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;
- 9 123 123 123 000 000 314 ÷ 2 = 4 561 561 561 500 000 157 + 0;
- 4 561 561 561 500 000 157 ÷ 2 = 2 280 780 780 750 000 078 + 1;
- 2 280 780 780 750 000 078 ÷ 2 = 1 140 390 390 375 000 039 + 0;
- 1 140 390 390 375 000 039 ÷ 2 = 570 195 195 187 500 019 + 1;
- 570 195 195 187 500 019 ÷ 2 = 285 097 597 593 750 009 + 1;
- 285 097 597 593 750 009 ÷ 2 = 142 548 798 796 875 004 + 1;
- 142 548 798 796 875 004 ÷ 2 = 71 274 399 398 437 502 + 0;
- 71 274 399 398 437 502 ÷ 2 = 35 637 199 699 218 751 + 0;
- 35 637 199 699 218 751 ÷ 2 = 17 818 599 849 609 375 + 1;
- 17 818 599 849 609 375 ÷ 2 = 8 909 299 924 804 687 + 1;
- 8 909 299 924 804 687 ÷ 2 = 4 454 649 962 402 343 + 1;
- 4 454 649 962 402 343 ÷ 2 = 2 227 324 981 201 171 + 1;
- 2 227 324 981 201 171 ÷ 2 = 1 113 662 490 600 585 + 1;
- 1 113 662 490 600 585 ÷ 2 = 556 831 245 300 292 + 1;
- 556 831 245 300 292 ÷ 2 = 278 415 622 650 146 + 0;
- 278 415 622 650 146 ÷ 2 = 139 207 811 325 073 + 0;
- 139 207 811 325 073 ÷ 2 = 69 603 905 662 536 + 1;
- 69 603 905 662 536 ÷ 2 = 34 801 952 831 268 + 0;
- 34 801 952 831 268 ÷ 2 = 17 400 976 415 634 + 0;
- 17 400 976 415 634 ÷ 2 = 8 700 488 207 817 + 0;
- 8 700 488 207 817 ÷ 2 = 4 350 244 103 908 + 1;
- 4 350 244 103 908 ÷ 2 = 2 175 122 051 954 + 0;
- 2 175 122 051 954 ÷ 2 = 1 087 561 025 977 + 0;
- 1 087 561 025 977 ÷ 2 = 543 780 512 988 + 1;
- 543 780 512 988 ÷ 2 = 271 890 256 494 + 0;
- 271 890 256 494 ÷ 2 = 135 945 128 247 + 0;
- 135 945 128 247 ÷ 2 = 67 972 564 123 + 1;
- 67 972 564 123 ÷ 2 = 33 986 282 061 + 1;
- 33 986 282 061 ÷ 2 = 16 993 141 030 + 1;
- 16 993 141 030 ÷ 2 = 8 496 570 515 + 0;
- 8 496 570 515 ÷ 2 = 4 248 285 257 + 1;
- 4 248 285 257 ÷ 2 = 2 124 142 628 + 1;
- 2 124 142 628 ÷ 2 = 1 062 071 314 + 0;
- 1 062 071 314 ÷ 2 = 531 035 657 + 0;
- 531 035 657 ÷ 2 = 265 517 828 + 1;
- 265 517 828 ÷ 2 = 132 758 914 + 0;
- 132 758 914 ÷ 2 = 66 379 457 + 0;
- 66 379 457 ÷ 2 = 33 189 728 + 1;
- 33 189 728 ÷ 2 = 16 594 864 + 0;
- 16 594 864 ÷ 2 = 8 297 432 + 0;
- 8 297 432 ÷ 2 = 4 148 716 + 0;
- 4 148 716 ÷ 2 = 2 074 358 + 0;
- 2 074 358 ÷ 2 = 1 037 179 + 0;
- 1 037 179 ÷ 2 = 518 589 + 1;
- 518 589 ÷ 2 = 259 294 + 1;
- 259 294 ÷ 2 = 129 647 + 0;
- 129 647 ÷ 2 = 64 823 + 1;
- 64 823 ÷ 2 = 32 411 + 1;
- 32 411 ÷ 2 = 16 205 + 1;
- 16 205 ÷ 2 = 8 102 + 1;
- 8 102 ÷ 2 = 4 051 + 0;
- 4 051 ÷ 2 = 2 025 + 1;
- 2 025 ÷ 2 = 1 012 + 1;
- 1 012 ÷ 2 = 506 + 0;
- 506 ÷ 2 = 253 + 0;
- 253 ÷ 2 = 126 + 1;
- 126 ÷ 2 = 63 + 0;
- 63 ÷ 2 = 31 + 1;
- 31 ÷ 2 = 15 + 1;
- 15 ÷ 2 = 7 + 1;
- 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.
9 123 123 123 000 000 314(10) = 111 1110 1001 1011 1101 1000 0010 0100 1101 1100 1001 0001 0011 1111 0011 1010(2)
4. Determine the signed binary number bit length:
The base 2 number's actual length, in bits: 63.
- 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, 63,
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:
9 123 123 123 000 000 314(10) = 0111 1110 1001 1011 1101 1000 0010 0100 1101 1100 1001 0001 0011 1111 0011 1010
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...
-9 123 123 123 000 000 314(10) Base 10 integer number converted and written as a signed binary code (in base 2):
-9 123 123 123 000 000 314(10) = 1111 1110 1001 1011 1101 1000 0010 0100 1101 1100 1001 0001 0011 1111 0011 1010
Spaces were used to group digits: for binary, by 4, for decimal, by 3.