What are the required steps to convert base 10 integer
number 5 310 122 340 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 310 122 340 ÷ 2 = 2 655 061 170 + 0;
- 2 655 061 170 ÷ 2 = 1 327 530 585 + 0;
- 1 327 530 585 ÷ 2 = 663 765 292 + 1;
- 663 765 292 ÷ 2 = 331 882 646 + 0;
- 331 882 646 ÷ 2 = 165 941 323 + 0;
- 165 941 323 ÷ 2 = 82 970 661 + 1;
- 82 970 661 ÷ 2 = 41 485 330 + 1;
- 41 485 330 ÷ 2 = 20 742 665 + 0;
- 20 742 665 ÷ 2 = 10 371 332 + 1;
- 10 371 332 ÷ 2 = 5 185 666 + 0;
- 5 185 666 ÷ 2 = 2 592 833 + 0;
- 2 592 833 ÷ 2 = 1 296 416 + 1;
- 1 296 416 ÷ 2 = 648 208 + 0;
- 648 208 ÷ 2 = 324 104 + 0;
- 324 104 ÷ 2 = 162 052 + 0;
- 162 052 ÷ 2 = 81 026 + 0;
- 81 026 ÷ 2 = 40 513 + 0;
- 40 513 ÷ 2 = 20 256 + 1;
- 20 256 ÷ 2 = 10 128 + 0;
- 10 128 ÷ 2 = 5 064 + 0;
- 5 064 ÷ 2 = 2 532 + 0;
- 2 532 ÷ 2 = 1 266 + 0;
- 1 266 ÷ 2 = 633 + 0;
- 633 ÷ 2 = 316 + 1;
- 316 ÷ 2 = 158 + 0;
- 158 ÷ 2 = 79 + 0;
- 79 ÷ 2 = 39 + 1;
- 39 ÷ 2 = 19 + 1;
- 19 ÷ 2 = 9 + 1;
- 9 ÷ 2 = 4 + 1;
- 4 ÷ 2 = 2 + 0;
- 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 310 122 340(10) = 1 0011 1100 1000 0010 0000 1001 0110 0100(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 310 122 340(10) Base 10 integer number converted and written as a signed binary code (in base 2):
5 310 122 340(10) = 0000 0000 0000 0000 0000 0000 0000 0001 0011 1100 1000 0010 0000 1001 0110 0100
Spaces were used to group digits: for binary, by 4, for decimal, by 3.