| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
C = bitget(A, bit)
C = bitget(A, bit) returns the value of the bit at position bit in A. Operand A must be an unsigned integer, a double, or an array containing unsigned integers, doubles or both. The bit input must be a number between 1 and the number of bits in the unsigned integer class of A (e.g., 32 for the uint32 class).
The dec2bin function converts decimal numbers to binary. However, you can also use the bitget function to show the binary representation of a decimal number. Just test successive bits from most to least significant:
disp(dec2bin(13))
1101
C = bitget(uint8(13), 4:-1:1)
C =
1 1 0 1Prove that intmax sets all the bits to 1:
a = intmax('uint8');
if all(bitget(a, 1:8))
disp('All the bits have value 1.')
end
All the bits have value 1.Get the value of the second most significant bit of the number sequence 5 through 75, counting by tens:
bitget(5:10:65, [2 3 4 5 5 5 6 7])
ans =
0 1 1 0 0 1 0 1Do 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 1
bitand, bitcmp, bitmax, bitor, bitset, bitshift, bitxor
![]() | bitcmp | bitmax | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |