Lesson 2 40 min

Hexadecimal and Octal

AI Explain — Ask anything
AI Illustrate — Make it visual

Why This Matters

This lesson explores hexadecimal (base-16) and octal (base-8) number systems, which are crucial for representing binary data more compactly and readably in computer science. Understanding these systems facilitates easier manipulation and comprehension of memory addresses, colour codes, and other low-level computer data.

Key Words to Know

01
Hexadecimal (Hex) — A base-16 number system using digits 0-9 and letters A-F to represent values 0-15.
02
Octal — A base-8 number system using digits 0-7.
03
Base (Radix) — The number of unique digits, including zero, used to represent numbers in a positional numeral system.
04
Binary — A base-2 number system using only digits 0 and 1.
05
Decimal — The standard base-10 number system we use daily.
06
Nibble — A group of four binary digits, equivalent to one hexadecimal digit.
07
Byte — A group of eight binary digits, equivalent to two hexadecimal digits.

Introduction to Number Bases

In computer science, while computers fundamentally operate using binary (base-2), humans find it challenging to read and write long strings of 0s and 1s. Hexadecimal (base-16) and octal (base-8) systems provide a more concise and human-readable way to represent binary data. They are 'shorthand' for binary, making it easier for programmers and engineers to work with memory addresses, machine code, and other low-level data. The key advantage is that conversions between binary and these bases are straightforward because their bases are powers of 2 (8 = 2^3, 16 = 2^4).

Key Idea: Each digit in a number system represents a power of its base. For example, in decimal, 123 = 110^2 + 210^1 + 310^0. This principle applies universally to all number bases, including binary, octal, and hexadecimal. Understanding this positional value is fundamental to performing conversions between different bases.

Hexadecimal (Base-16)

Hexadecimal uses 16 unique symbols: 0-9 and A-F. The letters A through F represent decimal values 10 through 15, respectively.

  • A = 10
  • B = 11
  • C = 12
  • D = 13
  • E = 14
  • F = 15

Conversion from Hex to Decimal: Multiply each hexadecimal digit by its corresponding power of 16 and sum the results. For example, 2AF_16: 2 * 16^2 + A * 16^1 + F * 16^0 2 * 256 + 10 * 16 + 15 * 1 512 + 160 + 15 = 687_10

Conversion from Decimal to Hex: Use repeated division by 16, keeping track of the remainders. The remainders, read from bottom to top, form the hexadecimal number. If a remainder is 10-15, convert it to its hex letter equivalent. Hexadecimal is widely used for memory addresses, MAC addresses, colour codes (e.g., #FF0000 for red), and displaying raw binary data.

Octal (Base-8)

Octal uses 8 unique symbols: 0, 1, 2, 3, 4, 5, 6, 7. It was historically used in computing, particularly with early minicomputers, as a compact representation of binary data. While less common than hexadecimal today, it's still relevant in some contexts, such as file permissions in Unix/Linux systems.

Conversion from Octal to Decimal: Multiply each octal digit by its corresponding power of 8 and sum the results. For example, 37_8: 3 * 8^1 + 7 * 8^0 3 * 8 + 7 * 1 24 + 7 = 31_10

Conversion from Decimal to Octal: Use repeated division by 8, collecting the remainders. The remainders, read from bottom to top, form the octal number. Octal's direct relationship with binary (each octal digit represents exactly three binary digits) makes conversions straightforward.

Binary to Hexadecimal/Octal Conversion

The primary reason for using hexadecimal and octal is their easy conversion to and from binary. This is due to their bas...

This section is locked

Hexadecimal/Octal to Binary Conversion

Converting from hexadecimal or octal back to binary is equally straightforward, simply reversing the grouping process.

...

This section is locked

2 more sections locked

Upgrade to Starter to unlock all study notes, audio listening, and more.

Exam Tips

  • 1.**Memorise Hex Equivalents:** Be able to quickly recall the decimal and 4-bit binary equivalents for hex digits A-F (e.g., F = 15 = 1111). This speeds up conversions significantly.
  • 2.**Practice Grouping:** For binary to hex/octal conversions, always group from the **right-hand side** first and pad with leading zeros on the left if necessary. Errors often occur when grouping from the left.
  • 3.**Show Your Working:** For multi-step conversions (e.g., Hex to Decimal, or Decimal to Binary/Hex/Octal), clearly show your division/multiplication steps and remainders. This helps earn partial credit even if the final answer is incorrect.
👋 Ask Aria anything!