- char buff[SIZE] = {0};
- char *p = buff;
- *(int *)p = 256;
以下是我在ruby中的解决办法(安全的C#的解决办法我会在下一篇博文中讲述):
- def ConvIntIntoArray(num)
- (num & 0xFF).chr +
- (num >> 8 & 0xFF).chr +
- (num >> 16 & 0xFF).chr +
- (num >> 24 & 0xFF).chr
- end
- def ConvArrayIntoInt(array)
- array[0].ord +
- (array[1].ord << 8) +
- (array[2].ord << 16) +
- (array[3].ord << 24)
- end
- def ConvShortIntoArray(num)
- (num & 0xFF).chr +
- (num >> 8 & 0xFF).chr
- end
- def ConvArrayIntoShort(array)
- array[0].ord +
- (array[1].ord << 8)
- end