How to convert from decimal to binary in matlab.....this is what I have so far.....

dec = 43;
i = 1;
sum=0;
while dec>0
r = rem(dec, 2);
sum=sum+(i*rem);
dec=dec/2;
i=i*10;
end
sum

1 answer

The logic looks correct except for one minor logic error in:
sum=sum+(i*rem);
which should read
sum=sum+i*r;

You need to make sure the statements execute correctly in Matlab syntax.
For example, an integer division can be written as
dec=dec./2;
or
dec=idivide(dec,2);

Also, be careful about overflow of the decimal representation of the binary number (sum), which has at least 3 times more digits as the decimal equivalent.
Similar Questions
  1. Decimal to binary convertionI Explain the way to Perform Decimal to Binary Conversion. II. Convert the following binary numbers
    1. answers icon 1 answer
  2. I.Explain the wayto Perform Decimal to Binary Conversion.g.(255)10 h.(256)10 steps f.(224)10 i.Take your own,at least 4
    1. answers icon 1 answer
  3. Question 2a.What is a Binary Number System? c.What is Binary to Decimal Conversion? d.How to Convert Binary to Decimal
    1. answers icon 1 answer
  4. BINARY TO DECIMAL CONVERSION:a.What is a Binary Number System? c.What is Binary to Decimal Conversion? d.How to Convert Binary
    1. answers icon 1 answer
more similar questions