Binary to Decimal Conversion Each binary bit (1 or 0) in a binary number has a weight that is a power of 2 just like the digits in decimal number that have weights in powers of ten. 27 26 25 24 23 22 21 20 1 1 1 1 1 1 1 1
104 103 102 101 100 9 9 9 9 9
20 = 1 21 = 2 22 = 4 23 = 8 24 =16 25 = 32 26 = 64 27 = 128
100 = 1 101 = 10 102 = 100 103 = 1,000 104 = 10,000
To convert a binary number i.e. 10102 you add up the weights of each bit that is 1 or in this example 8 + 2 = 10. If you do this for all combinations of 4 bits you get a table of the binary number system counting from 0 to 16. 0000 = 0 0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 1000 = 8 1001 = 9 1010 = 10 1011 = 11 1100 = 12 1101 = 13 1110 = 14 1111 = 15
In computer networking we normally deal in groups 8 bits referred to as a byte or octet. It is therefore very common to convert 8 bit binary numbers to decimal. Example: convert 101100102 to decimal. 128 64 32 16 8 4
2
1
1 0 1 1 0 0 1 0
add up the weights of the bits that are equal to 1.
128 + 32 + 16 + 2 = 17810 If all bits are 0 (00000000) then the decimal value is 0 and if all bits are 1 (11111111) the decimal value is 128+64+32+16+8+4+2+1=255. This gives us the range of possible decimal values for 8 bits or 1 byte of 0 to 25510. Example: Can 29810 be express as an 8 bit binary number? No it is greater than 255 and requires more bits. Example: Convert 001111002 to decimal. 128 64 32 16 8 4
2
1
0 0 1 1 1 1 0 0
add up the weights of the bits that are equal to 1.
32 + 16 + 8 + 4 = 6010 Example: Convert 011011012 to decimal. 128 64 32 16 8 4
2
1
0 1 1 0 1 1 0 1
add up the weights of the bits that are equal to 1.
64 +32 + 8 + 4 + 1 = 10910 Example: Convert 111100002 to decimal. 128 64 32 16 8 4
2
1
1 1 1 1 0 0 0 0
add up the weights of the bits that are equal to 1.
128 + 64 + 32 + 16 = 24010