close all;
clear all;
clc;

H=[1 0 1 1 0; 0 0 1 0 1; 1 0 0 1 0; 1 0 1 1 1]

[m,n]=size(H);
k=n-m;
for i=k+1:n
    %H(:,i)
    ind=find(H(:,i),1,'last');
    % exchanging (ind)th row and (i-k)th row
    if ind<i-k
        continue;
    end
    if ind~=i-k
        temp=H(ind,:);
        H(ind,:)=H(i-k,:);
        H(i-k,:)=temp;
    end
    I=find(H(:,i));
    % Guassian elimination
    for j=1:length(I)
        if I(j)~=i-k
            H(I(j),:)=mod(H(I(j),:)+H(i-k,:),2);
        end
    end
end
Hsys=H