Documentation

bitget

Get bit at specified position

Syntax

b = bitget(A,bit)
b = bitget(A,bit,assumedtype)

Description

example

b= bitget(A,bit)returns the bit value at positionbitin integer arrayA.

example

b= bitget(A,bit,assumedtype)assumes thatAis ofassumedtype.

Examples

collapse all

Find the difference in the binary representation between the maximum integer of signed and unsigned integers.

a1 = intmax('int8'); a2 = intmax(“uint8'); b1 = bitget(a1,8:-1:1)
b1 =1x8 int8 row vector0 1 1 1 1 1 1 1
b2 =bitget(a2,8:-1:1)
b2 =1x8 uint8 row vector1 1 1 1 1 1 1 1

The signed integers require a bit to accommodate negative integers.

Find the 8-bit representation of a negative number.

A = -29; b = bitget(A,8:-1:1,'int8')
b =1 1 1 0 0 0 1 1

Input Arguments

collapse all

Input values, specified as an array.Acan be a scalar or an array of the same size asbit.

  • IfAis a double array, andassumedtypeis not specified, then MATLAB®treatsAas an unsigned 64-bit integer.

  • Ifassumedtypeis specified, then all elements inAmust have integer values within the range ofassumedtype.

Data Types:double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Bit position, specified as an integer or integer array.bitcan be a scalar or an array of the same size asA.bitmust be between 1 (the least-significant bit) and the number of bits in the integer class ofA.

Data Types:double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Assumed data type ofA, specified as'uint64','uint32','uint16',“uint8','int64','int32','int16', or'int8'.

  • IfAis a double array, thenassumedtypecan specify any valid integer type, but defaults to'uint64'.

  • IfAis an integer type array, thenassumedtypemust specify that same integer type.

Data Types:char

Output Arguments

collapse all

Bit value atbit, returned as an array of0s and1s.bis the same data type asA.

  • IfAandbitare scalars, thenbis also a scalar.

  • If eitherAorbitis an array, thenbis the same size as that array.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?