go - What does the &^ operator do? -


according specification operator called bit clear:

&^   bit clear (and not)    integers 

i've never heard of such operator before, , i'm wondering why useful.

it seems take left operand , disables bits turned on in right operand. there formal description of operator? 1 more thing noticed it's not commutative. pseudocode in comarison ^:

11110 &^ 100 //11010 11110  ^ 100 //11010  11110 &^ 0 //11110 11110  ^ 0 //11110  11110 &^ 11110 //0 11110  ^ 11110 //0  11110 &^ 111 //11000 11110  ^ 111 //11001  111 &^ 11110 //1 111  ^ 11110 //11001 

from symbol (a concatenation of & , ^), name "and not" (and term "bit clear" sounds opposite of "bit set"), seems evident a &^ b doing a & ^b (where ^ bitwise inverse).

this backed examining operator's truth table:

fmt.println(0 &^ 0);    // 0 fmt.println(0 &^ 1);    // 0 fmt.println(1 &^ 0);    // 1 fmt.println(1 &^ 1);    // 0 

(see http://ideone.com/s4pfe9.)


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -