在MATLAB中无符号整型转二进制
(2012-02-23 00:08:20)
标签:
it |
分类: matlab |
bitget
Bit at specified position
Syntax
C =
Description
C =
The output of
Examples
Example 1 — Binary Conversion
The
disp(dec2bin(13)) 1101 C = bitget(uint8(13), 4:-1:1) C = 1 1 0 1
Example 2 — Binary Compare
Prove that
a = intmax('uint8'); if all(bitget(a, 1:8)) disp('All the bits have value 1.') end All the bits have value 1.
Example 3 — Vector and Array Operations
Get the value of the second most significant bit of the number sequence 5 through 75, counting by tens:
bitget(5:10:75, [2 3 4 5 5 5 6 7]) ans = 0 1 1 0 0 1 0 1
Do the same, but using 2-by-4 matrices:
bitget([5 15 25 35; 45 55 65 75], ... [2 3 4 5; 5 5 6 7]) ans = 0 1 1 0 0 1 0 1See Also
bitand,
dec2bin
Convert decimal to binary number in string
Syntax
str
=
str =
Description
returns the
str
=
str
=
The output of
Examples
Decimal 23 converts to binary 010111:
dec2bin(23) ans = 10111