我有一个Java代码中的方法,它会根据给定的整数返回字节数组:
private static byte[] intToBytes(int paramInt)
{
byte[] arrayOfByte = new byte[4];
ByteBuffer localByteBuffer = ByteBuffer.allocate(4);
localByteBuffer.putInt(paramInt);
for (int i = 0; i < 4; i++)
arrayOfByte[(3 - i)] = localByteBuffer.array()[i];
return arrayOfByte;
}
有人能给我一些提示,如何将这个方法转换为C++?
static_cast<>
而不是一个reinterpret_cast<>
? - PaulHreinterpret_cast
等效于一对static_cast
。如果我记得正确,基本上认为两者都应该始终有效,但是所有内容都非常复杂,所以我仍然避免使用reinterpret_cast
。 - James McNellis