필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Daljit Singh
Daljit Singh 2014년 6월 4일
답변: Stephen23 2017년 8월 25일
i tried number of functions but m not able to add these to numbers
  댓글 수: 2
Tom Rauber
Tom Rauber 2017년 8월 25일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2017년 8월 25일
>> 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

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by