开发者

How Can I Read a Large Integer from a Buffer into an Integer in iOS?

I am having difficulty getting an integer from a buffer in iOS.

To read 开发者_开发技巧a string, I am using:

output = [[NSString alloc] initWithBytes:buffer lenght:len encoding:NSASCIIStringEncoding];

But there doesn't seem to be an equivalent initWithBytes for integers.

Thanks in advance,

Dave


That is because the buffer can be cast directly to the integer value.

int original = 0xBADF00D;
void *buffer = &original;

//Cast the void* as an int* and then dereference the value
int intFromBuffer = *(int*)buffer;

NSLog(@"0x%X 0x%X", original, intFromBuffer);

Output:

0xBADF00D 0xBADF00D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜