Number Systems
Understand binary, decimal, octal and hexadecimal bases used in digital electronics.
Why several bases?
A digital circuit manipulates electrical levels interpreted as bits: 0 and 1. For humans, long binary strings quickly become hard to read. Hexadecimal and octal are compact notations that still map directly to bits.
| Base | Digits | Common use |
|---|---|---|
| 2, binary | 0, 1 | Real value seen by hardware |
| 10, decimal | 0 to 9 | Human reading, everyday calculations |
| 8, octal | 0 to 7 | Groups of 3 bits |
| 16, hexadecimal | 0 to 9, A to F | Groups of 4 bits, registers, buses |
The rule is always the same: each position has a weight. In base 2, the weights are 1, 2, 4, 8, 16, and so on.
Reading a binary number
The number 101101₂ is read by adding the weights of the bits set to 1:
| Bit | 1 | 0 | 1 | 1 | 0 | 1 |
|---|---|---|---|---|---|---|
| Weight | 32 | 16 | 8 | 4 | 2 | 1 |
101101₂ = 32 + 8 + 4 + 1 = 45₁₀In digital electronics, this is how you interpret a bus value, a memory address or a counter.
Decimal to binary
To convert a decimal integer to binary, divide by 2 and read the remainders from bottom to top.
Example with 45₁₀:
| Division | Quotient | Remainder |
|---|---|---|
| 45 / 2 | 22 | 1 |
| 22 / 2 | 11 | 0 |
| 11 / 2 | 5 | 1 |
| 5 / 2 | 2 | 1 |
| 2 / 2 | 1 | 0 |
| 1 / 2 | 0 | 1 |
45₁₀ = 101101₂The rightmost bit is the LSB (least significant bit). The leftmost bit is the MSB (most significant bit).
Hexadecimal: bus notation
Hexadecimal is common because one hexadecimal digit represents exactly 4 bits.
| Hex | Binary | Decimal |
|---|---|---|
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | |
Example:
0x2D = 0010 1101₂ = 45₁₀On an FPGA, a 32-bit bus is often written as 8 hexadecimal digits:
constant C_MASK : std_logic_vector(31 downto 0) := x"0000_FF00";Octal: groups of 3 bits
Octal groups bits by sets of 3. It is less common than hexadecimal in modern FPGA projects, but it is useful to recognize.
101101₂ = 101 101₂ = 55₈Each group ranges from 000₂ to 111₂, therefore from 0₈ to 7₈.
Binary fractions
Bits to the right of the binary point have fractional weights:
| Position | Weight |
|---|---|
2^-1 | 0.5 |
2^-2 | 0.25 |
2^-3 | 0.125 |
2^-4 | 0.0625 |
101.01₂ = 4 + 1 + 0.25 = 5.25₁₀This idea appears in digital filters, PWM, fixed-point arithmetic and DSP blocks.
VHDL points to watch
The binary value is not enough: you also need its type and width.
signal count_u : unsigned(7 downto 0);
signal data_s : signed(7 downto 0);
signal flags : std_logic_vector(7 downto 0);unsignedrepresents a positive integer.signedrepresents a two's-complement signed integer.std_logic_vectoris only a packet of bits: its meaning depends on context.
Two buses may contain the same bits while representing different values. This is a common source of mistakes in comparisons, additions and width extensions.
Key points
- Hardware manipulates bits, but humans use compact notations.
- Hexadecimal is the natural format for wide buses.
- A numeric value is understood through its base, width and interpretation.
- In VHDL, choosing
unsigned,signedorstd_logic_vectorclarifies the circuit intent.
📝 Test your knowledge - Chapter quiz