Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Compute Hamming distance

Hardware interview practice

Compute Hamming distance

EasyBit ManipulationSystemVerilog

Return the number of bit positions where two 32-bit integers differ.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
left = 4'b1010, right = 4'b0011
Expected output
2

The XOR is 1001, which contains two set bits.

What to cover

Requirements

  1. Use XOR to expose mismatches.
  2. Count the set bits in the XOR result.
Continue practicing

Related questions

Bit ManipulationCount set bits with Kernighan's method→Bit ManipulationFind the single non-duplicate→
asic.fyi · Learn silicon end to end.info@asic.fyi