Binary addition matlab

Status
Not open for further replies.

Chinmaye

Full Member level 3
Joined
Jan 18, 2016
Messages
164
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
3,145
Hello all,
I am trying to add 2 binary numbers in matlab. Here is my code.

Code:
a = [0,0,0,1];
b = [0,0,0,0];
  sum= str2double(num2cell(dec2bin(bin2dec(num2str(a))+bin2dec(num2str(b)))));

Though i get the sum as 1, i would like to get it in the form
sum= [0,0,0,1];
Please help.
 

you can use bi2de and de2bi. there is a 'left-msb' argument to avoid the need for fliplr.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…