Reputation: 2087
I need to combine the binary representation of 6 and 7 together:
bin1 = fliplr(de2bi(6));
bin2 = fliplr(de2bi(7));
bin1 =
1 1 0
bin2 =
1 1 1
after the combination the number should be
bin3 = 110111
Does anyone have any idea on how to do this?
Upvotes: 0
Views: 1998
Reputation: 21563
As suggested you can just concatenate them
bin3 = [bin1, bin2]
However, if you really want them packed together without spaces you can do it like this:
bin3 = num2str([bin1, bin2]);
bin3 = bin3(bin3 ~= ' ')
If you want to turn them in to a number now you can use str2num()
Upvotes: 1