There are quite a few encoding techniques used in modern ASIC design. In this post, we will cover RTL implementations of 3 must know encoding techniques.
Binary / 1-Hot Encoding
To implement binary to 1-hot encoding, using 3-bit binary number for example:
logic [2:0] bin;
logic [7:0] oneHot;
assign oneHot = 8’b1 << bin;
It is a good practice to write an SVA, making sure “oneHot” is truly 1-hot encoded, by using SystemVerilog built-in function $onehot().
Conversely, to implement 1-hot to binary encoding:
always_comb begin
bin = ‘0;
for (int i = 0; i < 8; i++)
if (oneHot[i])
bin = 3’(i);
end
We strongly recommend interviewees to keep such implementations in mind, as this is often brought up during RTL / ASIC design interviews.
Binary / Gary Encoding
Gray encoding ensures that only one bit changes between successive encoded values. This characteristic makes gray encoding quite useful in clock domain crossing (CDC), async FIFO pointer implementation, as well as a power reduction technique where reducing toggling is desired.
To implement binary to gray encoding, using 3-bit binary number for example:
logic [2:0] bin;
logic [2:0] gray;
assign gray = (bin >> 1) ^ bin;
Conversely, to implement gray to binary encoding:
always_comb begin
for (int i = 0; i < 3; i++)
bin[i] = ^(gray >> i);
end
Again, we strongly recommend interviewees to keep these implementations in mind.
The 8b / 10b encoding is mainly used in serial data transfer protocols, such as PCIe Gen1 & Gen2, where 8b input data is converted to 10b symbols used in actual data transfers. In the data receiving block, the 10b symbol is decoded back to 8b data.
Serial data transfer protocols do not transfer clocks along with data, and they recover / restructure clocks from data. The 8b / 10b encoding scheme provides a sufficient distribution of 1s and 0s, and removes repetitive occurrences of 1s and 0s. This is crucial for reliable clock recovery.
Note, for every 10 bits of transmitted data, only 8 bits are useful. This translates to a 20% overhead. Other encoding variants are adopted to overcome this overhead. For example, 10G Ethernet protocols use 64b / 66b encoding, and PCIe Gen3 uses 128b / 130b encoding.

Leave a comment