Java 给定范围内数字的XORing

Java 给定范围内数字的XORing,java,algorithm,xor,Java,Algorithm,Xor,在这个给定范围内的数字xor的程序中,我无法理解他们如何找到数字xor的算法。如果有人解释一下这个算法是如何在这个范围内找到xor值的,那就太好了 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /*This program is used to find the xor of numbers within the range u can enter mu

在这个给定范围内的数字xor的程序中,我无法理解他们如何找到数字xor的算法。如果有人解释一下这个算法是如何在这个范围内找到xor值的,那就太好了

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*This program is used to find the xor of numbers within the range

u can enter multiple inputs.Here first enter the numbers of inputs u want to enter then in the next line enter the starting and ending range of the xoring 
numbers with space

for example : 

Input :
1
2 3

output:

odd


output displays whether the xor value  within the given range is odd r not

*/

class XORNEY {
    public static void main(String[] args) throws IOException {
        BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
        int testCases = Integer.parseInt(kb.readLine());
        StringBuilder output = new StringBuilder();

        while (testCases-- > 0) {
            //here without declaring the array dynamically how they are storing all the inputs
            String[] input = kb.readLine().trim().split(" ");  

            long L = Long.parseLong(input[0]);
            long H = Long.parseLong(input[1]);
            //i am more confused here abt why they are doing this
            long count = (H - L) / 2;   
            if ((L & 1) == 1 || (H & 1) == 1) count++;
            output.append((count & 1) == 1 ? "Odd\n" : "Even\n");
        }

        System.out.print(output);
    }
}
这里不需要动态声明数组的存储方式 所有输入

它们只是存储每个测试用例行,而不是所有的输入。每行由两个由空格分隔的数字组成,如果按空格分割,则两个数字都会出现在一个数组中

我对他们为什么这样做更感到困惑

我可以提供一些想法-

在一系列数字中,您将得到以0和1序列交替结尾的二进制数。例如—

  • 10->******0
  • 11->******1
  • 12->******0
  • 13->******1
对于每对
0,1
XOR
将为1。现在你需要弄清楚你是得到偶数对还是奇数对。偶数对将产生偶数1到XOR,并给您一个以
0
结尾的值,这意味着最终的
XOR
值是一个
偶数。而另一方面是奇数

如果在该范围内有偶数个元素,则可以确定有一些
(0,1)
。但是如果它是奇怪的,根据额外的项目是
0/1
,您的计算需要调整。

1.查看文档split()返回的内容。是一个字符串数组。所以创建并填充数组只需抓取即可。(返回类型必须匹配obj声明)。这就是算法。(假设很好:数学)。请注意,如果在使用复合检查和on true计数后,计数将增加。如果为真[计数]加1。如果为假[计数]&-这只是一种使用位操作检查奇偶校验的方法(使用%2也可以实现同样的效果)