Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nolte authored Feb 7, 2023
1 parent 0f5c063 commit f7cf039
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hamming.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
%function y = hamming(x,y)
%Hamming binary distance between non-negative decimal integers x and y

function hsum = hamming(x,y)

sx = ceil(log2(x+1));
sy = ceil(log2(y+1));
sz = max(sx,sy);

xb = dec2bin(x);
yb = dec2bin(y);

z = bitxor(x,y);

sum = 0;
for loop = 1:sz
sum = sum + bitget(z,loop);
end

hsum = sum;

0 comments on commit f7cf039

Please sign in to comment.