/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Bitwise Operations //Turn a bit on int startVal = 4; //100 int bitVal = 2; //010 int newVal = startVal | bitVal; //110 (6) //Alternatively startVal |= bitVal; //Turn a bit off int startVal = 7; //111 int bitVal = 5; //101 int newVal = startVal & bitVal; //101 (5) //Alternatively startVal &= bitVal; //Query bit status int startVal = 6; //110 int bitVal = 4; //100 int newVal = startVal & bitVal; //100 if(newVal != 0) { //Bit was on. } int startVal = 6; //110 int bitVal = 1; //001 int newVal = startVal & bitVal; //000 if(newVal == 0) { //Bit was off. }