in go lang, why this is 7 ?
assert(5^2 == 7)
so strange. I tried to google it. but google does not work well with special characters. Thanks.
The ^ operator is the XOR (exclusive OR), applied bitwise if operands are numbers.
5 = 101b // in binary, but Go doesn't have binary literals
2 = 010b
XOR:
7 = 111b
It is an Arithmetic operators:
^ bitwise XOR integers
You can see it on this Bitwise Calculator
Result in binary 111
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With