0

我有以下数组:

static const int8_t ARRAY[8] = {0x18, 0xB8, 0xCE, 0x0, 0x0, 0x0, 0x0, 0x0};

我需要得到一个整数值。对于这个ARRAY最终int值是13547544,因为数组中的字节,后面的顺序相反little-endian

例子0xCEB818 = 13547544

我怎样才能做到这一点?可以有现成的标准溶液吗?

提前致谢!

4

1 回答 1

2

Since the host platform is little-endian, you can just point a 64-bit integer pointer at the array and the machine will read the array correctly.

static const int8_t ARRAY[8] = {0x18, 0xB8, 0xCE, 0x0, 0x0, 0x0, 0x0, 0x0};
uint64_t *value = (uint64_t *)&ARRAY;

NSLog(@"%llu", *value); // outputs 13547544
于 2014-08-06T14:36:11.397 回答