What are the required steps to convert base 10 integer
number -12 697 160 277 502 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:
|-12 697 160 277 502| = 12 697 160 277 502
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;
- 12 697 160 277 502 ÷ 2 = 6 348 580 138 751 + 0;
- 6 348 580 138 751 ÷ 2 = 3 174 290 069 375 + 1;
- 3 174 290 069 375 ÷ 2 = 1 587 145 034 687 + 1;
- 1 587 145 034 687 ÷ 2 = 793 572 517 343 + 1;
- 793 572 517 343 ÷ 2 = 396 786 258 671 + 1;
- 396 786 258 671 ÷ 2 = 198 393 129 335 + 1;
- 198 393 129 335 ÷ 2 = 99 196 564 667 + 1;
- 99 196 564 667 ÷ 2 = 49 598 282 333 + 1;
- 49 598 282 333 ÷ 2 = 24 799 141 166 + 1;
- 24 799 141 166 ÷ 2 = 12 399 570 583 + 0;
- 12 399 570 583 ÷ 2 = 6 199 785 291 + 1;
- 6 199 785 291 ÷ 2 = 3 099 892 645 + 1;
- 3 099 892 645 ÷ 2 = 1 549 946 322 + 1;
- 1 549 946 322 ÷ 2 = 774 973 161 + 0;
- 774 973 161 ÷ 2 = 387 486 580 + 1;
- 387 486 580 ÷ 2 = 193 743 290 + 0;
- 193 743 290 ÷ 2 = 96 871 645 + 0;
- 96 871 645 ÷ 2 = 48 435 822 + 1;
- 48 435 822 ÷ 2 = 24 217 911 + 0;
- 24 217 911 ÷ 2 = 12 108 955 + 1;
- 12 108 955 ÷ 2 = 6 054 477 + 1;
- 6 054 477 ÷ 2 = 3 027 238 + 1;
- 3 027 238 ÷ 2 = 1 513 619 + 0;
- 1 513 619 ÷ 2 = 756 809 + 1;
- 756 809 ÷ 2 = 378 404 + 1;
- 378 404 ÷ 2 = 189 202 + 0;
- 189 202 ÷ 2 = 94 601 + 0;
- 94 601 ÷ 2 = 47 300 + 1;
- 47 300 ÷ 2 = 23 650 + 0;
- 23 650 ÷ 2 = 11 825 + 0;
- 11 825 ÷ 2 = 5 912 + 1;
- 5 912 ÷ 2 = 2 956 + 0;
- 2 956 ÷ 2 = 1 478 + 0;
- 1 478 ÷ 2 = 739 + 0;
- 739 ÷ 2 = 369 + 1;
- 369 ÷ 2 = 184 + 1;
- 184 ÷ 2 = 92 + 0;
- 92 ÷ 2 = 46 + 0;
- 46 ÷ 2 = 23 + 0;
- 23 ÷ 2 = 11 + 1;
- 11 ÷ 2 = 5 + 1;
- 5 ÷ 2 = 2 + 1;
- 2 ÷ 2 = 1 + 0;
- 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.
12 697 160 277 502(10) = 1011 1000 1100 0100 1001 1011 1010 0101 1101 1111 1110(2)
4. Determine the signed binary number bit length:
The base 2 number's actual length, in bits: 44.
- 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, 44,
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:
12 697 160 277 502(10) = 0000 0000 0000 0000 0000 1011 1000 1100 0100 1001 1011 1010 0101 1101 1111 1110
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...
-12 697 160 277 502(10) Base 10 integer number converted and written as a signed binary code (in base 2):
-12 697 160 277 502(10) = 1000 0000 0000 0000 0000 1011 1000 1100 0100 1001 1011 1010 0101 1101 1111 1110
Spaces were used to group digits: for binary, by 4, for decimal, by 3.