bitget function working explanation needed

6 ビュー (過去 30 日間)
Manu Chaudhary
Manu Chaudhary 2022 年 1 月 15 日
回答済み: Steven Lord 2022 年 1 月 15 日
I am completely new to matlab. I am really not able to understand bitget.
The sample code given on the matlab website is:
a1 = intmax('int8');
a2 = intmax('uint8');
b1 = bitget(a1,8:-1:1)
This code is giving me output as
b1 =
1×8 int8 row vector
0 1 1 1 1 1 1 1
Even after seeing the output, I am not being able to interpret the working of bitget. It would be great if someone can explain me this.

採用された回答

Steven Lord
Steven Lord 2022 年 1 月 15 日
Here's an unsigned 8-bit integer.
x = 0b10011010u8 % x is 10011010
x = uint8 154
The lowest order bit of x is 0. This makes sense since x is even.
bitget(x, 1)
ans = uint8 0
The next three highest order bits (bits 4, 3, and 2) are 1, 0, and 1 respectively.
bitget(x, [4 3 2])
ans = 1×3
1 0 1
Here are all the bits.
bitget(x, 8:-1:1) % x's binary representation is 10011010
ans = 1×8
1 0 0 1 1 0 1 0

その他の回答 (0 件)

カテゴリ

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