Understand how and why hexadecimal is used as a beneficial method of data representation

Data Representation: Hexadecimal 🔢

In computer science, we often need a compact way to write binary numbers. Hexadecimal (base‑16) is the perfect tool because it maps neatly onto binary while being shorter and easier to read.

Why Use Hexadecimal? 🧩

Compactness: One hex digit = 4 binary bits. • Readability: Easier to spot patterns than long binary strings. • Alignment with memory: Computers store data in bytes (8 bits). Two hex digits represent one byte, which matches how memory addresses are displayed. • Common in programming: Hex is used for colours, memory addresses, error codes, etc.

Hex Basics 📦

Hexadecimal uses 16 symbols: 0–9 and A–F (where A=10, B=11, …, F=15). The value of a hex number is calculated as: $$\displaystyle \text{value} = \sum_{i=0}^{n-1} d_i \times 16^i$$ where \(d_i\) is the digit at position \(i\) (rightmost digit has \(i=0\)).

  • Hex digit “A” = 10 in decimal.
  • Hex digit “F” = 15 in decimal.
  • Hex “10” = \(1 \times 16^1 + 0 \times 16^0 = 16\).

Converting Binary to Hex 🔄

1. Group the binary number into 4‑bit chunks from the right. 2. Replace each chunk with its hex digit.

  1. Take binary: 11010110 00101101
  2. Group: 1101 0110 0010 1101
  3. Convert each group:
    • 1101 → D
    • 0110 → 6
    • 0010 → 2
    • 1101 → D
  4. Resulting hex: D62D
Binary Chunk Hex Digit
1101 D
0110 6
0010 2
1101 D

Hex in Memory and Networking 📡

Memory addresses: A computer’s RAM is addressed in bytes. Hex makes it easy to read addresses like 0x1A3F instead of a long binary string. • Colour codes: Web colours use hex (e.g., #FF5733). • Network packets: Hex dumps show packet contents clearly for debugging.

Practice Problems 📝

  1. Convert binary 10111001 01100110 to hexadecimal.
  2. What is the decimal value of hex 4B7?
  3. Write the hex representation of the ASCII character “A” (decimal 65).
  4. Explain why hex is preferred over binary when writing memory addresses.

Revision

Log in to practice.

1 views 0 suggestions