Shifting operations and bitwise logical operations with binary numbers

1 回表示 (過去 30 日間)
srikanth
srikanth 2013 年 4 月 10 日
Hi friends, Actually i need to do right shifting of a binary numbers.
For Example:
a=200
b=dec2bin(200)
c=str2num(b)
d=bitshift(c,3)
Binary of 200 is 11001000. If i right shift it by 3 i should get 00011001 but d is giving 88008000. Even "bitsll" command is not giving desired results.
In addition to this i also need to work with bitwise logical operators.I tried in different ways using( "and" , "&" , "&&") but nothing is working.
Please suggest me the right way of working with above mentioned operations with binary numbers.
Thanks

採用された回答

Walter Roberson
Walter Roberson 2013 年 4 月 10 日
a8 = uint8(200);
d = bitshift(a8, 3);
If you insist on working with dec2bin representation, then
a8 = uint8(200);
b = dec2bin(a8, 8);
d = ['0' '0' '0' b(1:end-3)];

その他の回答 (3 件)

Yao Li
Yao Li 2013 年 4 月 10 日
編集済み: Yao Li 2013 年 4 月 10 日
a=200
b=bitshift(a,-3)
c=dec2bin(b,8)

Iman Ansari
Iman Ansari 2013 年 4 月 10 日
編集済み: Iman Ansari 2013 年 4 月 10 日
a=200
b=dec2bin(200)
c=shift(b,3)

srikanth
srikanth 2013 年 4 月 10 日
Thanks for your help guys. Both 1st and 2nd replies are working

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by