You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
y= (x>>n)&1; // stores nth bit of x in y. y becomes 0 or 1.x&=~(1<<n); // forces nth bit of x to be 0. all other bits left alone.x&=(1<<(n+1))-1; // leaves lowest n bits of x; all higher bits set to 0.x|=(1<<n); // forces nth bit of x to be 1. all other bits left alone.x^=(1<<n); // toggles nth bit of x. all other bits left alone.x=~x; // toggles ALL the bits in x.
Reverse the Bits in a Byte
/// <summary>/// return a byte with all of its bits in reverse order/// </summary>publicstaticbyteReverseBits(byteb1){byteb2=0;for(inti=0;i<8;i++){b2+=(byte)(((b1>>i)&1)<<7-i);}returnb2;}