I'm having trouble converting strings that represent binary numbers to decimal and vice versa. The main issue is that I'm unsure of how to deal with the decimal point, say converting -11.11 to decimal. This is a homework assignment, so I'm not allowed to use the built in functions.
Here's my code for one of the two:
function decimal= mybin2real(binarystring)decimal = 0;for i = 1 : length(binarystring)decimal = decimal + str2num(binarystring(i)) * 2^(length(binarystring) - i);enddecimalend
I was thinking about finding where the decimal point was using strfind, but i'm not sure how to implement it in the matlab code.
Best Answer