What are the required steps to convert base 10 integer
number 12 939 052 834 995 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;
- 12 939 052 834 995 ÷ 2 = 6 469 526 417 497 + 1;
- 6 469 526 417 497 ÷ 2 = 3 234 763 208 748 + 1;
- 3 234 763 208 748 ÷ 2 = 1 617 381 604 374 + 0;
- 1 617 381 604 374 ÷ 2 = 808 690 802 187 + 0;
- 808 690 802 187 ÷ 2 = 404 345 401 093 + 1;
- 404 345 401 093 ÷ 2 = 202 172 700 546 + 1;
- 202 172 700 546 ÷ 2 = 101 086 350 273 + 0;
- 101 086 350 273 ÷ 2 = 50 543 175 136 + 1;
- 50 543 175 136 ÷ 2 = 25 271 587 568 + 0;
- 25 271 587 568 ÷ 2 = 12 635 793 784 + 0;
- 12 635 793 784 ÷ 2 = 6 317 896 892 + 0;
- 6 317 896 892 ÷ 2 = 3 158 948 446 + 0;
- 3 158 948 446 ÷ 2 = 1 579 474 223 + 0;
- 1 579 474 223 ÷ 2 = 789 737 111 + 1;
- 789 737 111 ÷ 2 = 394 868 555 + 1;
- 394 868 555 ÷ 2 = 197 434 277 + 1;
- 197 434 277 ÷ 2 = 98 717 138 + 1;
- 98 717 138 ÷ 2 = 49 358 569 + 0;
- 49 358 569 ÷ 2 = 24 679 284 + 1;
- 24 679 284 ÷ 2 = 12 339 642 + 0;
- 12 339 642 ÷ 2 = 6 169 821 + 0;
- 6 169 821 ÷ 2 = 3 084 910 + 1;
- 3 084 910 ÷ 2 = 1 542 455 + 0;
- 1 542 455 ÷ 2 = 771 227 + 1;
- 771 227 ÷ 2 = 385 613 + 1;
- 385 613 ÷ 2 = 192 806 + 1;
- 192 806 ÷ 2 = 96 403 + 0;
- 96 403 ÷ 2 = 48 201 + 1;
- 48 201 ÷ 2 = 24 100 + 1;
- 24 100 ÷ 2 = 12 050 + 0;
- 12 050 ÷ 2 = 6 025 + 0;
- 6 025 ÷ 2 = 3 012 + 1;
- 3 012 ÷ 2 = 1 506 + 0;
- 1 506 ÷ 2 = 753 + 0;
- 753 ÷ 2 = 376 + 1;
- 376 ÷ 2 = 188 + 0;
- 188 ÷ 2 = 94 + 0;
- 94 ÷ 2 = 47 + 0;
- 47 ÷ 2 = 23 + 1;
- 23 ÷ 2 = 11 + 1;
- 11 ÷ 2 = 5 + 1;
- 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.
12 939 052 834 995(10) = 1011 1100 0100 1001 1011 1010 0101 1110 0000 1011 0011(2)
3. 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.
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:
12 939 052 834 995(10) Base 10 integer number converted and written as a signed binary code (in base 2):
12 939 052 834 995(10) = 0000 0000 0000 0000 0000 1011 1100 0100 1001 1011 1010 0101 1110 0000 1011 0011
Spaces were used to group digits: for binary, by 4, for decimal, by 3.