hexor's blog

By hexor, 11 years ago, In English

Can you give me a some trick for xor( exclusive or ) operation?

  • Vote: I like it
  • +17
  • Vote: I do not like it

»
11 years ago, # |
  Vote: I like it +9 Vote: I do not like it
»
11 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Given an array of positive integers. Let's assume that every value except one repeat an even number of times. The question is: find the only value that repeats an odd number of times.

For example, if the array is: 6 8 8 6 3 9 3 9 3 the answer is 3, because it repeats an odd number of times.

For the solution, see "Rev. 1" of this comment :)

»
11 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Here you can find some tricks for bit operations http://graphics.stanford.edu/~seander/bithacks.html