What is the easiest way to bit mask a 16 bit binary value to decode different fields (2 bit, 4 bit, etc) with it? Thanks

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 11 月 16 日

0 投票

bitand(), bitor(),

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 11 月 16 日

1 投票

You could use bitand() and bitshift() too. Or just bitget().
Watch out for the bit numbering order that MATLAB uses.

3 件のコメント

Nevin
Nevin 2011 年 11 月 16 日
Thanks Walter. But with bitget() I can't get multiple bits just one? Correct?
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 16 日
You can get multiple bits.
bitget(7,1:3)
thinnawat chumpuwiset
thinnawat chumpuwiset 2018 年 8 月 17 日
i'm still confuse about bitget(), can you describe more detail?

サインインしてコメントする。

Fangjun Jiang
Fangjun Jiang 2018 年 8 月 17 日

0 投票

>> dec2bin(7,8)
ans =
'00000111'
>> bitget(7,1:8)
ans =
1 1 1 0 0 0 0 0

製品

タグ

質問済み:

2011 年 11 月 16 日

回答済み:

2018 年 8 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by