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

8-bit number 0xB6 = 1011 01101706151403121100
8-bit number 0xB6 = 1011 0110

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.

BinaryHexDecimal
000000
010155
1010A10
1111F15
1 00001016
1111 1111FF255
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...

2. One hex digit equals how many bits?