0

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?

1
  • 4
    why not simply concatenate them? bin3 = [bin1, bin2] Commented Nov 12, 2012 at 16:50

1 Answer 1

1

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()

Sign up to request clarification or add additional context in comments.

1 Comment

Even shorter: num2str(bin3, '%d')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.