Last active
September 28, 2017 20:28
-
-
Save KristupasSavickas/8b96d252d2baacedb6cdbdd408113148 to your computer and use it in GitHub Desktop.
Generates all n bit long binary numbers
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
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