【发布时间】:2013-06-30 09:11:34
【问题描述】:
我有一个CFBitVector,看起来像'100000000000000'
我将字节数组传递给CFBitVectorGetBits,然后它包含来自此CFBitVector 的值。在这个电话之后,bytes[2] 看起来像:
bytes[0] == '0x80'
bytes[1] == '0x00'
这正是我所期望的。但是,当将bytes[2] 的内容复制到unsigned int bytesValue, 时,值应该是128,而它应该是32768。十进制值128 由十六进制值0x0080 表示。本质上,执行memcpy 时似乎字节顺序颠倒了。这里发生了什么?这只是字节顺序的问题吗?
谢谢
CFMutableBitVectorRef bitVector = CFBitVectorCreateMutable(kCFAllocatorDefault, 16);
CFBitVectorSetCount(bitVector, 16);
CFBitVectorSetBitAtIndex(bitVector, 0, 1);
CFRange range = CFRangeMake(0, 16);
Byte bytes[2] = {0,0};
unsigned int bytesValue = 0;
CFBitVectorGetBits(bitVector, range, bytes);
memcpy(&bytesValue, bytes, sizeof(bytes));
return bytesValue;
【问题讨论】:
标签: c++ objective-c memory endianness memcpy