Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-158

Hamming Distance of Blocks

Problem

Return the Hamming distance in bits between two equal-length byte lists: sum over positions of the number of differing bits in a[i] XOR b[i].

Hint

XOR isolates the differing bits; popcount then counts them.

Test cases

case 1
in: [[0,0],[0,0]]
expected: 0
case 2
in: [[255,0],[0,255]]
expected: 16
case 3
in: [[1,2],[3,4]]
expected: 3
case 4
in: [[170],[85]]
expected: 8
Starter codePython
def hamming_distance_bytes(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor