How do i convert base-2 number with decimal point into base-10?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Samson David Puthenpeedika
el 30 de Oct. de 2021
Respondida: John D'Errico
el 30 de Oct. de 2021
Convert t base-2 numbers to base-10:
a. 110.01001
i tried using syntax bin2dec but it was giving error:
a='110.01001'
bin2dec(a)
0 comentarios
Respuestas (2)
Walter Roberson
el 30 de Oct. de 2021
split the character vector at the '.' and dec2bin() the two parts independently. Now divide the second one by 2^(number of digits), and add the result to the first converted value.
0 comentarios
John D'Errico
el 30 de Oct. de 2021
BIN2DEC does NOT support numbers with a decimal point in them. You can want it to happen, but it won't. Wanting code to behave as it was not designed to do is often a waste of time and want.
However, if you delete the decimal point, you will implicitly convert the number into an integer. Then you could remember where the decimal point fell, and divide by an appropriate power of 2. For example:
a = '110.01001';
decloc = find(a == '.')
b = a; b(decloc) = '';
X = bin2dec(b)/2^(numel(a) - decloc)
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!