Network Number System Conversions: Binary, Decimal, Hexadecimal

Introduction to Number Systems in Networking* Physical Layer & Bits: At the physical layer of a network, data is converted into electrical or optical signals representing ones and zeros (bits), which are the fundamental units of information that travel across networks. All internal computer operations use binary.

  • Human vs. Computer Representation: While computers operate in binary, they often display information like IP addresses to humans in decimal (base 10) for easier readability and understanding.

Types of Network Addresses

  • MAC Addresses & IP Addresses: These are the primary types of addresses used in networking.

    • MAC addresses: 48 binary bits in length.

    • IPv6 addresses: 128 binary bits in length.

    • IPv4 addresses: Each segment, separated by a period, is a decimal number between 00 and 255255. Internally, each of these decimal numbers is represented by eight binary bits.

  • Need for Conversions: Binary strings for addresses (especially MAC and IPv6) are extremely long and difficult for humans to read and write. Therefore, conversion to other number systems like decimal or hexadecimal (base 16) is necessary for human accessibility.

Decimal (Base 10) Number System

  • Place Value & Powers of 10: In decimal, each digit's position represents a power of 1010. Starting from the rightmost digit:

    • Rightmost digit: Base to the power of zero (100=1)(10^0 = 1)

    • Next digit to the left: Base to the power of one (101=10)(10^1 = 10)

    • Next digit: Base to the power of two (102=100)(10^2 = 100) and so on.

  • Example: 59210592_{10}

    • 22 in the (100)(10^0) place: 2imes100=2imes1=22 imes 10^0 = 2 imes 1 = 2

    • 99 in the (101)(10^1) place: 9imes101=9imes10=909 imes 10^1 = 9 imes 10 = 90

    • 55 in the (102)(10^2) place: 5imes102=5imes100=5005 imes 10^2 = 5 imes 100 = 500

    • Sum: 500+90+2=592500 + 90 + 2 = 592

Binary (Base 2) Number System

  • Core Concept: Powers of 2: Similar to decimal, binary uses powers of its base, which is 22. Digits can only be 00 or 11.

    • Rightmost bit: 20=12^0 = 1

    • Next bit: 21=22^1 = 2

    • Next bit: 22=42^2 = 4

    • Next bit: 23=82^3 = 8

    • And so on, for higher powers.

  • Bits and Bytes: An octet is a group of eight binary bits, commonly used to represent each segment of an IPv4 address (e.g., 02550-255).

  • Binary to Decimal Conversion

    • Method: For each bit, multiply the bit value (0(0 or 1)1) by its corresponding power of 22. Then, sum all the results.

    • Example: 101021010_2 to Decimal

      • 0imes20=0imes1=00 imes 2^0 = 0 imes 1 = 0

      • 1imes21=1imes2=21 imes 2^1 = 1 imes 2 = 2

      • 0imes22=0imes4=00 imes 2^2 = 0 imes 4 = 0

      • 1imes23=1imes8=81 imes 2^3 = 1 imes 8 = 8

      • Sum: 8+0+2+0=10108 + 0 + 2 + 0 = 10_{10}

    • Example: 110121101_2 to Decimal

      • 1imes20=1imes1=11 imes 2^0 = 1 imes 1 = 1

      • 0imes21=0imes2=00 imes 2^1 = 0 imes 2 = 0

      • 1imes22=1imes4=41 imes 2^2 = 1 imes 4 = 4

      • 1imes23=1imes8=81 imes 2^3 = 1 imes 8 = 8

      • Sum: 8+4+0+1=13108 + 4 + 0 + 1 = 13_{10}

    • Example: 010120101_2 to Decimal

      • 1imes20=1imes1=11 imes 2^0 = 1 imes 1 = 1

      • 0imes21=0imes2=00 imes 2^1 = 0 imes 2 = 0

      • 1imes22=1imes4=41 imes 2^2 = 1 imes 4 = 4

      • 0imes23=0imes8=00 imes 2^3 = 0 imes 8 = 0

      • Sum: 0+4+0+1=5100 + 4 + 0 + 1 = 5_{10}

  • Decimal to Binary Conversion (Cisco Method)

    • Method: This method typically aims for an 8-digit binary representation because IP addresses use octets. (You always start with 202^0 on the right and increase powers to the left.)

      1. List the powers of 22 from 272^7 down to 202^0 (decimal equivalents: 128,64,32,16,8,4,2,1128, 64, 32, 16, 8, 4, 2, 1).

      2. Starting from the largest power of 22 (128128), ask if it can be subtracted from the decimal number.

      3. If YES: Place a 11 in the binary position for that power of 22, subtract the power of 22 from the decimal number, and use the remainder for the next step.

      4. If NO: Place a 00 in the binary position for that power of 22.

      5. Continue this process until all powers of 22 down to 202^0 have been evaluated.

    • Example: 16810168_{10} to Binary

      • 128128: Can subtract 128128 from 168168? Yes. Binary: 11. Remainder: 168128=40168 - 128 = 40

      • 6464: Can subtract 6464 from 4040? No. Binary: 00. Remainder: 4040

      • 3232: Can subtract 3232 from 4040? Yes. Binary: 11. Remainder: 4032=840 - 32 = 8

      • 1616: Can subtract 1616 from 88? No. Binary: 00. Remainder: 88

      • 88: Can subtract 88 from 88? Yes. Binary: 11. Remainder: 88=08 - 8 = 0

      • 44: Can subtract 44 from 00? No. Binary: 00. Remainder: 00

      • 22: Can subtract 22 from 00? No. Binary: 00. Remainder: 00

      • 11: Can subtract 11 from 00? No. Binary: 00. Remainder: 00

      • Result: 10101000210101000_2

    • Example: 781078_{10} to Binary

      • 128128: No (00) (Remainder 7878)

      • 6464: Yes (11) (Remainder 7864=1478 - 64 = 14)

      • 3232: No (00) (Remainder 1414)

      • 1616: No (00) (Remainder 1414)

      • 88: Yes (11) (Remainder 148=614 - 8 = 6)

      • 44: Yes (11) (Remainder 64=26 - 4 = 2)

      • 22: Yes (11) (Remainder 22=02 - 2 = 0)

      • 11: No (00) (Remainder 00)

      • Result: 01001110201001110_2

    • Example: 24210242_{10} to Binary

      • 128128: Yes (11) (Remainder 242128=114242 - 128 = 114)

      • 6464: Yes (11) (Remainder 11464=50114 - 64 = 50)

      • 3232: Yes (11) (Remainder 5032=1850 - 32 = 18)

      • 1616: Yes (11) (Remainder 1816=218 - 16 = 2)

      • 88: No (00) (Remainder 22)

      • 44: No (00) (Remainder 22)

      • 22: Yes (11) (Remainder 22=02 - 2 = 0)

      • 11: No (00) (Remainder 00)

      • Result: 11110010211110010_2

Hexadecimal (Base 16) Number System

  • Purpose: Hexadecimal is used to efficiently represent very long binary numbers found in MAC addresses (48 bits) and IPv6 addresses (128 bits). It minimizes the number of digits needed.

  • Hex Digits: Hex uses 090-9 and letters AFA-F to represent decimal values 101510-15:

    • 10<em>10=A</em>1610<em>{10} = A</em>{16}

    • 11<em>10=B</em>1611<em>{10} = B</em>{16}

    • 12<em>10=C</em>1612<em>{10} = C</em>{16}

    • 13<em>10=D</em>1613<em>{10} = D</em>{16}

    • 14<em>10=E</em>1614<em>{10} = E</em>{16}

    • 15<em>10=F</em>1615<em>{10} = F</em>{16}

  • Hextet: In IPv6, each grouping between colons is called a