While testing for a program, I found that
0 xor 1 xor 2 xor ... xor 1000000 = 1000000
and it is true for the numbers in this form except for 10:
1 1 true
10 11 false
100 100 true
1000 1000 true
10000 10000 true
100000 100000 true
1000000 1000000 true
10000000 10000000 true
100000000 100000000 true
1000000000 1000000000 true
(the true means it follows the rule and false means it doesn't).
Is there any theorem that is related to this? And what is so special about the number 10?
The program in Ruby if you are interested to try out:
n = 1
10.times do
r = (0..n).inject(:^)
puts "#{n} #{r} #{n == r}"
n *= 10
end
a^bmean bitwise xor between the decimal integersaandbafter converting them to binary? – AgentS Aug 19 '19 at 03:26