比特获取
bit at特定位置
同步
c=位获取(a,位) ) )。
描述
c=bitget(a,bit ) returns
the value of the bit at
定位字节。
OperandAmust be an
unsigned integer,a double,or an array containing unsigned
integers,双精度or both。
Thebitinput
mustbeanumberbetween1andthenumberofbitsintheunsigned
集成类
OFA(e.g .32 for
the uint 32类)。
The output ofbitgetis
independentoftheendiansettingsofthecomputeryouare
使用。
Examples
example1-二进制转换
Thedec2binfunction
convertsdecimalnumberstobinary.however,you can also use
thebitgetfunction
toshowthebinaryrepresentationofadecimalnumber.just test
successivebitsfrommosttoleastsignificant :
DISP(DEC2bin(13 ) ) 1101 c=比特获取(uint8) 13 ),4:-1:1 ) C=1 1 0 1 ) 10
example 2—二进制比较
保护阈值矩阵
all the bits to 1:
a=intmax(uint8); ifall (位get (a,1:8 ) ) disp ) ' allthebitshavevalue1. ' ' end all the bits have value 1。
example3- vectorandarrayoperations
getthevalueofthesecondmostsignificantbitofthenumber
sequence 5 through 75,counting by tens:
bitget(5:10:75,[234556 ) ans=0 1 1 0 0 1 0 1
Do the same,but using 2-by-4 matrices:
位get ([ 5152535; 45 55 65 75], [2 3 4 5; 56 )7) ans=0 1 1 0 0 1 0 1
See Also
bitand,bitcmp,bitmax,bitor,bitset,bitshift,bitxor
c=
位获取(2,5:-1:1 ) ) )。
c=
0
0 0 1
0
dec2bin
convertdecimaltobinarynumberinstring
同步
str
=DEC2bin(d ) ) )。
str=deC2bin(d,n ) ) ) ) ) ) ) )。
描述
returns the
str
=DEC2bin(d ) binary
representation ofdas a
string.dmust be a nonnegative
integer smaller than 2^52。
str
=DEC2bin(d,n ) produces
a binary representation with at
最后一位。
theoutputofdec 2二进制独立
theendiansettingsofthecomputeryouareusing。
Examples
decimal 23转换器010 111:
DEC2bin(23 ) ans=10111