Sign in

Learn

Practice

Know this already? Skip to the exercise: Power-Up Defaults in Binary and Hex

Binary and Hexadecimal

Binary represents values using bits, each either 0 or 1. Four of them are enough to describe a device's status code, read from left to right with weights 8, 4, 2, and 1.

Quick check

Read a status word

Question 1 of 1

Bits and buses

In digital hardware, voltage ranges represent logic values. A bit describes one binary value and a bus groups several of them. An eight-bit parallel bus carries all eight at once rather than one bit per program instruction.

Width matters because each extra bit doubles the number of possible patterns. N bits provide 2^N patterns, which as unsigned values cover 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. Decimal 9 needs four bits, 1001, and 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, and A through F stand for ten through fifteen.

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

Group binary digits in fours, starting from the right, so 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, and 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, which means they describe the three outputs together rather than as three actions separated in time.

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

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

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

When the requirement changes

Quick check

How many bits do you need?

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, and in the waveform bin_o, hex_o, and dec_o show the same value and remain flat.

The waveform viewer may display all three as hexadecimal. That is a display choice in the viewer, and it does not mean 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.