Skip to Main Content Skip to Search
Product Documentation

bitget - Bit at certain position

Syntax

c = bitget(a, bit)

Description

c = bitget(a, bit) returns the value of the bit at position bit in a as a u1,0 (unsigned integer of word length 1). bit must be an integer between 1 and the word length of a, inclusive. If a has a signed numerictype, the bit representation of the stored integer is in two's complement representation.

bitget only supports fi objects with fixed-point data types. bitget does not support inputs with complex data types.

bitget supports variable indexing. This means that bit can be a variable instead of a constant.

a and bit can be vectors or scalars. a and bit must be the same size unless one is a scalar. If a is a vector and bit is a scalar, c is a vector of u1,0 values of the bits at position bit in each fi object in a. If a is a scalar and bit is a vector, c is a vector of u1,0 values of the bits in a at the positions specified in bit.

bit does not need to be a vector of sequential bit positions.

Examples

Example 1

This example shows how to get the binary representation of the bit at a specific position in a fi object. Consider the following unsigned fixed-point fi object with a value of 85, word length 8, and fraction length 0:

a = fi(85,0,8,0);
disp(bin(a))

01010101

Get the binary representation of the bit at position 4:

bit4 = bitget(a,4);
disp(bin(bit4))

0

Example 2

This example shows how to get the binary representation of the bits at a vector of positions in a fi object. Consider the following signed fixed-point fi object with a value of 55, word length 16, and best-precision fraction length 9:

a = fi(55);
disp(bin(a))

0110111000000000

Get the binary representation of the bits at positions 16, 14, 12, 10, 8, 6, 4, and 2:

bitvec = bitget(a,[16:-2:1]);
disp(bin(bitvec))

0 1 1 1 0 0 0 0

See Also

bitand | bitcmp | bitor | bitset | bitxor

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS