Please I need help in MATLAB!!
1 次查看(过去 30 天)
显示 更早的评论
I have to write a function that changes binary numbers to decimal numbers without using loops and without using the function bin2dec.
1 个评论
Adam
2016-10-25
If you have to write the function then write it. Then come and ask for help once you have made some effort.
回答(2 个)
xiexiezaijian
2016-10-25
since no loops and no bin2dec, this work could be done using the definition of binary number and vecterization operation. Take binary number 101 for example:
a = 101;
b = str2num(num2str(a)');
c = 2.^(2:-1:0)*b;%get the decimal number here
it is easy to handle the binary number with 4 or more digits and even numbers with points.
It seems that this is a question in MATLAB Cody.....
2 个评论
xiexiezaijian
2016-10-26
If no str2num......maybe you could do like this;
a = 101;
b = num2str(101) - '0';% since '1'-'0' = 1;
c = 2.^(2:-1:0)*b';
really like a Cody problem....
Walter Roberson
2016-10-25
Hint: 2 to the 0, 2 to the 1, 2 to the 2, 2 to the 3... is 2 to the vector 0:3. Multiply each of those by the corresponding digit of the input and add the results
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!