failed binary to decimal
Mostra commenti meno recenti
hello everyone, I have the code below , which I want to use for conversion of binary to decimal, but each time I run the program, the software keeps saying >> binary_conversion
Not enough input arguments.
Error in binary_conversion (line 2)
count=numberofdigits(x);
Please I need held on this.
Here is the code:
function decimal_value= binary_conversion(x)
count=numberofdigits(x);
pow=0;
decimal_value=0;
for i=1:1:count
n=mod(x,10);
decimal_value=decimal_value+(n*2^pow);
pow=pow+1;
x=floor(x/10);
end
end
Risposte (1)
How do you try to run the code? Using the green triangle in the editor? Then now input argument is used.
Call it from the command line or from another script or function with an input:
d = binary_conversion(10010101)
A simplification of your code:
function d = binary_conversion(x)
count = numberofdigits(x);
mult = 1;
d = 0;
for i = 1:count
d = d + mod(x, 10) * mult;
mult = mult * 2;
x = floor(x / 10);
end
end
Categorie
Scopri di più su Serial Port (RS232) Protocol Blocks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!