MATLAB Function Reference Previous page   Next Page
bitset

Set bit at specified position

Syntax

Description

C = bitset(A, bit) sets bit position bit in A to 1 (on). A must be an unsigned integer or an array of unsigned integers, and bit 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).

C = bitset(A, bit, v) sets the bit at position bit to the value v, which must be either 0 or 1.

Examples

Example 1

Setting the fifth bit in the five-bit binary representation of the integer 9 (01001) yields 11001, or 25:

Example 2

Repeatedly subtract powers of 2 from the largest uint32 value:

See Also

bitand, bitcmp, bitget, bitmax, bitor, bitshift, bitxor


Previous page  bitor bitshift Next page

© 1994-2005 The MathWorks, Inc.