Sign in

Learn

Practice

Try the challenge first: Power-Up Defaults in Binary and Hex

Know this topic? Give it a go. The lesson is here if you need it.

Binary and Hexadecimal

Binary represents values using bits, each either 0 or 1. A group of four bits can describe a device's status code. Read the positions from left to right with weights 8, 4, 2, and 1.

Decode the status before learning another notation

Question 1 of 1

Bits and buses

In digital hardware, voltage ranges represent logic values. A bit describes one binary value; a bus groups several bits. An eight-bit parallel bus carries eight bits at once, not one bit per program instruction.

Width matters because each extra bit doubles the number of possible patterns. N bits provide 2^N patterns. When interpreted as unsigned, their range is zero through 2^N - 1.

WidthNumber of patternsUnsigned range
1 bit20 through 1
4 bits160 through 15
8 bits2560 through 255
16 bits65,5360 through 65,535

The circuit's bus width does not grow when the value becomes larger. For example, decimal 9 needs four bits: 1001. On an eight-bit bus, the same value is 00001001.

You will declare these widths in Entities and Modules.

Hexadecimal is a shorter spelling

One hexadecimal digit represents four bits. Digits zero through nine keep their familiar values; A through F represent ten through fifteen.

HexBinaryHexBinary
0000081000
1000191001
20010A1010
30011B1011
40100C1100
50101D1101
60110E1110
70111F1111

Group binary digits in fours, starting from the right. 10100101 becomes 1010 0101, or hexadecimal A5. Its decimal value is 128 + 32 + 4 + 1 = 165.

You can also convert an eight-bit decimal value directly: 60 = 3 × 16 + 12. The quotient is 3 and the remainder is C, giving hexadecimal 3C.

These are different spellings of the same bit pattern. Hexadecimal notation does not change the circuit.

Write a fixed value in HDL

The following assignments drive the same eight-bit value on three outputs. They are concurrent: they describe outputs together, not three actions separated in time.

bin_o <= "10100101";
hex_o <= x"A5";
dec_o <= 8D"165";

A binary literal has one character per bit. Each hex digit in x"A5" represents four bits. The VHDL-2008 decimal form 8D"165" explicitly requests eight bits. For twelve bits containing decimal 2026, use 12D"2026". Match the literal width to the output width.

Here the expressions are constants, so the outputs remain constant. Later assignments can depend on changing inputs.

Change the requirement

256 possible values is not a maximum value of 256

Question 1 of 1

bits

Verify the spelling in the waveform

Open One Value, Three Ways in the example panel on the right. Its literal_bases source contains the three assignments above. Compare bin_o, hex_o, and dec_o in the waveform: they show the same value and remain flat.

The waveform viewer may display all three as hexadecimal. That is a display choice, not evidence that the binary or decimal source was ignored. The power-up defaults exercise asks you to encode different fixed values.

Key Takeaways

  • Binary positions have powers-of-two weights; a fixed width limits the available patterns.
  • One hexadecimal digit groups four bits without changing their value.
  • State widths deliberately and check the largest required value, including boundary values.
Loading editor...
No waveform is available for this example. You can continue with the lesson and example code.