Monday, June 29, 2020

Bit Position Formula

Left Shift:
Formula: n*2^x = n*pow(2,x);
where n is number and x is bit positon.

Right Shift:
Formula: n/2^x = n/pow(2,x);
Where n is number and x is bit positon.

Xth Position Bit On:
Formula: n|(1<<x)
where x is positon of bit.

Xth Position Bit Off:
Formula: n&(~(1<<x))
where x is positon of bit.

Xth Positon Bit Check:
Formula: n&(1<<x)
where x is positon of bit.

if(n&(1<<x) == 0) that means bit off
otherwise on

No comments:

Post a Comment