Mathematics.

positional numeral systems

Number Representations (Binary, Hex)

Discrete Mathematics22 minDifficulty2 out of 10

You should know: integers

Overview

A number representation (positional numeral system) writes an integer as a sequence of digits, where each digit's contribution to the total value depends on both the digit and its position — its place value is a power of the system's base (radix). The familiar decimal system uses base 10 with digits 0–9, but any integer b ≥ 2 works as a base: binary (base 2, digits 0–1) is the native language of digital circuits, since a bit's two states map directly onto 'off' and 'on'; hexadecimal (base 16, digits 0–9 then A–F for 10–15) is popular in computing because each hex digit corresponds to exactly 4 bits, making it a compact, human-readable stand-in for binary. The same integer has a different digit string in each base, but converting between bases is mechanical: repeated division by the target base (to convert to that base) or summing digit × base^position (to convert from that base to decimal).

Intuition

Positional notation is an accounting trick: instead of one symbol per quantity (like tally marks), a digit's meaning is multiplied by where it sits, the way $1, $10, and $100 bills all use the same face value system but differ by position (power of 10). Binary is the same idea with only two denominations, 1 and 2, 4, 8, 16... (powers of 2) instead of 1, 10, 100...; converting decimal to binary by repeated division by 2 is just asking 'is there a $1 bill left over? a $2? a $4?' one denomination at a time, from the smallest up. Hexadecimal exists purely for human convenience: because 16 = 2⁴, every group of exactly 4 bits maps to one hex digit with no leftover boundary crossing, so hex strings are a shorthand for binary that's roughly 4 times shorter and much easier for people to read and type.

Formal Definition

Definition

In base b, a string of digits dₖdₖ₋₁...d₁d₀ (each dᵢ satisfying 0 ≤ dᵢ < b) represents the integer given by summing each digit times its place value:

N=i=0kdibi,0di<bN = \sum_{i=0}^{k} d_i \, b^i, \qquad 0 \le d_i < b
Value of a base-b digit string
N=(((dkb+dk1)b+dk2)b+)b+d0N = (\ldots((d_k b + d_{k-1})b + d_{k-2})b + \cdots)b + d_0
Horner's method (evaluate left to right)
binary: b=2, di{0,1};hex: b=16, di{0,,9,A,,F}\text{binary: } b = 2,\ d_i \in \{0,1\}; \qquad \text{hex: } b = 16,\ d_i \in \{0,\ldots,9,A,\ldots,F\}
Binary and hexadecimal digit sets
1 hex digit4 bits, since 16=241 \text{ hex digit} \leftrightarrow 4 \text{ bits, since } 16 = 2^4
Hex-to-binary shortcut

Worked Examples

  1. Repeatedly divide by 2, recording remainders from last to first.

    156=2(78)+0, 78=2(39)+0, 39=2(19)+1, 19=2(9)+1, 9=2(4)+1, 4=2(2)+0, 2=2(1)+0, 1=2(0)+1156 = 2(78)+0,\ 78=2(39)+0,\ 39=2(19)+1,\ 19=2(9)+1,\ 9=2(4)+1,\ 4=2(2)+0,\ 2=2(1)+0,\ 1=2(0)+1
  2. Reading the remainders from bottom (last division) to top (first division) gives the binary digits.

    15610=100111002156_{10} = 10011100_2

Answer: 156 in decimal equals 10011100 in binary.

Practice Problems

Difficulty 2/10

Convert the binary number 101101 to decimal.

Difficulty 3/10

Convert the decimal number 45 to hexadecimal.

Difficulty 4/10

A color in a web page is written in hex as #9C2D3F, where each pair of hex digits is one of the red, green, blue channels (0-255 each). What is the decimal value of the red channel, 9C?

Quiz

In base b, the place value of the digit in position i (counting from 0 at the rightmost digit) is:
Why does exactly one hex digit correspond to exactly 4 binary bits?
Converting a decimal integer to base b is typically done by:

Summary

  • A positional numeral system in base b represents N = Σ dᵢ bᵢ, with each digit dᵢ satisfying 0 ≤ dᵢ < b.
  • Binary (base 2) matches the two-state nature of digital circuits; hexadecimal (base 16) is a compact stand-in since 16 = 2⁴.
  • Converting decimal to base b uses repeated division by b, reading remainders from last to first.
  • Every group of exactly 4 binary bits corresponds to exactly one hexadecimal digit, with no boundary overlap.

References