我想读取一个二进制文件并对每个字节进行一些操作。我想测试我正在操纵字节。我想将字节变量1设置为“00000000”,然后将另一个字节变量2设置为“00001111”,或者将它们设置为newvariable = variable1 | variable2,将新的变量< <移位4位,然后打印出int值。JAVA字节操作
byte a = 00000000;
//Convert first oneByte to 4 bits and then xor with a;
byte b = 00001111;
byte c = (byte)(a|b);
c = c << 4;
System.out.println("byte= " + c + "\n");
我不知道为什么我不断收到“incompatiable类型:可能有损转换从byte到int”
您也可以阅读https://docs.oracle.com/javase/8/docs/technotes/guides/language/binary-literals.html –