num_digits = 3;
bit_divisor = 2.^(0:num_digits-1);
bit = zeros(2^num_digits,num_digits);
for combination = 0 : 2^num_digits - 1,
for nd = 1:num_digits,
% just bit shift to right and mask the right-most bit
bit(combination+1,num_digits-nd+1) = rem(floor(combination/bit_divisor(nd)), 2)
end
end % combination loop
No comments:
Post a Comment