如何在java中将变量拆分为单个字节?例如,我在 C++ 中有以下代码段:
unsigned long someVar;
byte *p = (byte*)(void*) someVar; // byte being typedef unsigned char (from 0 to 255)
byte *bytes = new byte[sizeof(someVar)];
for(byte i = 0;i<sizeof(someVar);i++)
{
bytes[i] = *p++;
}
.... //do something with bytes
我想在java下完成同样的事情,但我似乎找不到明显的解决方法。