Skip to Main Content Skip to Search
Product Documentation

bitset - Set bit at certain position

Syntax

c = bitset(a, bit)
c = bitset(a, bit, v)

Description

c = bitset(a, bit) sets bit position bit in a to 1 (on).

c = bitset(a, bit, v) sets bit position bit in a to v. v must have a value 0 (off) or 1 (on). Any value v other than 0 is automatically set to 1.

bit must be a number 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.

bitset only supports fi objects with fixed-point data types. a can be a scalar fi object or a vector fi object. bit and v can be scalars or vectors.

Examples

This example shows how to set a bit of a fi object. Consider the following unsigned fixed-point fi object with a value of 5, word length 4, and fraction length 0:

a = fi(5,0,4,0);
disp(bin(a))

0101

Set the bit at position 2 to 1:

c = bitset(a,2,1);
disp(bin(c))

0111

See Also

bitand | bitcmp | bitget | bitor | 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