Java 是否可以一次对4字节执行异或操作

Java 是否可以一次对4字节执行异或操作,java,Java,我需要对表示为单个字节的4个字节执行异或操作 b[0]=97; b[1]=98; b[2]=99; b[3]=100; int temp=0; int temp1=0; int temp2=0; int temp3=0; int temp4=0; temp1=temp1|b[0]; temp1=temp1<<24; temp2=temp2|b[1]; temp2=temp2<<16; temp3=temp3|b[2]; temp3=temp3<<8; temp

我需要对表示为单个字节的4个字节执行异或操作

b[0]=97;
b[1]=98;
b[2]=99;
b[3]=100;
int temp=0;
int temp1=0;
int temp2=0;
int temp3=0;
int temp4=0;
temp1=temp1|b[0];
temp1=temp1<<24;
temp2=temp2|b[1];
temp2=temp2<<16;
temp3=temp3|b[2];
temp3=temp3<<8;
temp4=temp4|b[3];
temp=temp4|temp3|temp2|temp1;
b[0]=97;
b[1]=98;
b[2]=99;
b[3]=100;
内部温度=0;
int temp1=0;
int temp2=0;
int temp3=0;
int temp4=0;
temp1=temp1 | b[0];
temp1=temp1

现在,如果需要,可以再次将其转换为整数。但是从我对你的问题的理解来看,你实际上想要的是
byte[]
格式。

如果没有任何代码,我怀疑你会得到比以下更好的答案:是的,创建一个小方法,将你的字节拆分为4个字节,并用XOR来测试它们……嗯?4个字节表示为单个字节?你必须澄清一下。你不能把你的4个字节打包成int和XOR吗?你不能把4个字节表示成1个字节,它们不合适。出于同样的原因,您也不能将整数表示为字节。它不合适。但我很好奇,为什么不能一个字节一个字节地进行异或运算呢?
// Assuming you have 2 byte arrays that you want to XOR
byte[] ba1 = new byte[4];
byte[] ba2 = new byte[4];

// Just filling up with arb. values
ba1[0] = 99;
ba1[1] = 100;
ba1[2] = 101;
ba1[3] = 102;

ba2[0] = 10;
ba2[1] = 11;
ba2[2] = 12;
ba2[3] = 13;

// To store the XOR in ba1 (or new byte[] if you want)
ba1[0] = ba1[0] ^ ba2[0];
ba1[1] = ba1[1] ^ ba2[1];
ba1[2] = ba1[2] ^ ba2[2];
ba1[3] = ba1[3] ^ ba2[3];