Home / Learn Verilog / Number Systems for Hardware: Binary, Octal, Decimal, Hex
Number Systems for Hardware: Binary, Octal, Decimal, Hex
Every signal in a chip is a binary number; hex makes it readable.
The short versionEvery signal in a chip is a binary number; hex makes it readable.
Theory in plain words
Definition
Computers store numbers in binary (base 2). Hexadecimal (base 16) is a compact way to write binary: one hex digit equals four bits.
Why you need this
You will read and write binary and hex values in every testbench, waveform and register map.
How it works
Each bit has a weight of a power of two. 1011 = 8 + 2 + 1 = 11. Group bits in fours from the right to get hex digits: 1011 0110 = B6.
Where you'll see this
- Reading waveforms
- Memory addresses
- Register maps
Convert in Verilog
Print a number in every baseVerilog: edit and run
The for loop prints a small conversion table. Change the step from 3 to 1.
| Binary | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0101 | 5 | 5 |
| 1010 | A | 10 |
| 1111 | F | 15 |
| 1 0000 | 10 | 16 |
| 1111 1111 | FF | 255 |
Tip:Learn the 16 hex digits and their 4-bit patterns. You will use them every day.
Test what you just read
1. Binary 1010 in hex is...
1010 = 10 = A.
2. One hex digit equals how many bits?
A nibble.