You may need to Set /Clear/Toggle multiple bit using C/C++ in your application. Let us see how we can achieve this in this tutorial.

Refer this before going down

Formula

Register_Value = Register_Value | (1<<X)

Register_Value = Register_Value & (~(1<<X))

Register_Value = Register_Value ^ (1<<X)

In all the listed formula above has common thing as 1<<X

here X is the position of the bit you want to set/clear/toggle

and 1 means binary one that is 1 bit

If you want to select two bit use 3<<X

3 in binary is 11

Cheers!!!!

-> Let Us Embed <-

Refer this before going down

Formula

Register_Value = Register_Value | (1<<X)

Register_Value = Register_Value & (~(1<<X))

Register_Value = Register_Value ^ (1<<X)

In all the listed formula above has common thing as 1<<X

here X is the position of the bit you want to set/clear/toggle

and 1 means binary one that is 1 bit

If you want to select two bit use 3<<X

3 in binary is 11

Cheers!!!!

-> Let Us Embed <-