Borrar filtros
Borrar filtros

I want to add two binary numbers 11111101 and 0.1000, please help me..

4 visualizaciones (últimos 30 días)
Daljit Singh
Daljit Singh el 4 de Jun. de 2014
Respondida: Stephen23 el 25 de Ag. de 2017
i tried number of functions but m not able to add these to numbers
  2 comentarios
Tom Rauber
Tom Rauber el 25 de Ag. de 2017
253.1000 is not correct, if 0.1000 is a binary number.
0.1 as a binary number means 2^(-1) = 0.5.
Hence the correct answer is 253.5

Iniciar sesión para comentar.

Respuestas (1)

Stephen23
Stephen23 el 25 de Ag. de 2017
>> binf2dec('11111101')+binf2dec('0.1')
ans =
253.5
Where
function dec = binf2dec(bin)
tkn = regexp(bin,'^([01]+)\.?([01]*)$','tokens','once');
vec = [tkn{:}]-'0';
dec = sum(vec.*pow2((numel(vec):-1:1)-1-numel(tkn{2})));
end

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by