I want to add two binary numbers 11111101 and 0.1000, please help me..
11 ビュー (過去 30 日間)
古いコメントを表示
i tried number of functions but m not able to add these to numbers
2 件のコメント
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
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!