Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Matlab-Programs-for-Nonlinear-Dynamics/hamming.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20 lines (14 sloc)
317 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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; |