Binary-to-decimal conversion calculates a decimal value by adding the positional values of every bit set to 1. For IPv4, work with four separate 8-bit groups rather than all 32 bits at once. section 7.2.2
Figure 7.4 An 8-bit (1-byte) number with the value of each bit written above. The decimal equivalent of 0b10101101 is 0d173. This can be calculated by adding the value of each bit that is set to 1.
Use the bit-value figure to identify each position’s decimal value before adding the values of the set bits. section 7.2.2
Convert an 8-bit binary number as follows:
- Write the positional values from left to right: 128, 64, 32, 16, 8, 4, 2, and 1. section 7.2.2
- Ignore positions containing 0, then add the values of positions containing 1. section 7.2.2
- Check that the result falls between 0 and 255; eight bits provide 256 possible values. section 7.2.2
Worked example
For 00101111, add 32 + 8 + 4 + 2 + 1. The decimal result is 47. Practice with random 8-bit values until the calculation becomes mental. section 7.2.2
