Go: What is doing?

Hope this question is not too stupid. I have no idea what the ^ operator does in Go, for example.

a := 3^500

At first I thought it should be pow , but it certainly is not. This is not mod (%).

I tried to browse the document and search on Google, but unfortunately Google does not consider ^ be a search query.

+7
operators go
source share
1 answer

As with most languages, the carriage operator is a broken XOR. You use it for integers.

Relevant Golang Documentation

Wikipedia on beaten xor:

A bitwise XOR takes two bit patterns of equal length and performs a logical exclusive OR for each pair of corresponding bits. the result in each position is 1 if only the first bit is 1 or only the second bit is 1, but it will be 0 if both are 0 or both are 1. In this, we compare two bits equal to 1 if the two bits are different, and 0 if they are the same

Bitwise XOR can be used to invert selected bits in a register (also called a switch or flip). Any bit can be switched by XORing with 1. For example, given bit pattern 0010 (decimal code 2), the second and fourth bits can be switched bitwise XOR with a bit scheme containing 1 in the second and fourth positions:

  0010 (decimal 2) XOR 1010 (decimal 10) = 1000 (decimal 8) 

This method can be used to manipulate bit patterns representing sets of Boolean states.

+16
source share

All Articles