代码:
byte[] aa = new byte[8];
aa = IntToByteArray2(101);
public byte[] IntToByteArray2(int value)
{
byte[] src = new byte[4];
src[0] = (byte)((value >> 24) & 0xFF);
src[1] = (byte)((value >> 16) & 0xFF);
src[2] = (byte)((value >> 8) & 0xFF);
src[3] = (byte)(value & 0xFF);
return src;
}
转换后的src 显示
[0]
[0]
[0]
[101]
这是为什么,
我稍微改了一下
#include <iostream>
using namespace std;
byte *IntToByteArray2(int value)
{
byte *src = new byte[4];
src[0] = (byte)((value >> 24) & 0xFF);
src[1] = (byte)((value >> 16) & 0xFF);
src[2] = (byte)((value >> 8) & 0xFF);
src[3] = (byte)(value & 0xFF);
return src;
}
int main(int argc, char const *argv[])
{
byte *aa = new byte[8];
aa = IntToByteArray2(101);
for (int i = 0; i < 4; i++)
{
cout << hex << int(aa[i]);
}
}