Bitwise addition if bit is 1.but not gettin answer.
古いコメントを表示
I am taking one number and converting it into binary and checking each bit whether it is 1 and if it is 1 then is added to next bit which is 1 and result is stored in c.
clc;
q=347;
q=dec2bin(q)
n=size(q,2)
c='0'
for i=1:n
if q(i)==1
c=c+q(i)
end
end
採用された回答
その他の回答 (1 件)
Amit
2013 年 12 月 27 日
0 投票
The question is unclear. Can you elaborate?
One issue I see is that q(i) == '1' and not q(i) == 1. As q is a string and not an integer.
カテゴリ
ヘルプ センター および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!