Skip to content

Instantly share code, notes, and snippets.

@KristupasSavickas
Last active September 28, 2017 20:28
Show Gist options
  • Save KristupasSavickas/8b96d252d2baacedb6cdbdd408113148 to your computer and use it in GitHub Desktop.
Save KristupasSavickas/8b96d252d2baacedb6cdbdd408113148 to your computer and use it in GitHub Desktop.
Generates all n bit long binary numbers
clc; clear all;
function generate_binaries(n)
B = zeros(2^n, n);
for i = n:-1:1
st = 2 ^ (n - i);
for j = st:2 * st:2^n
for k = 1:st
B(j + k, i) = 1;
end
end
end
B
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment