【发布时间】:2016-12-26 08:51:36
【问题描述】:
我有 2 个字节的温度值,例如: [0x0C, 0xDE] 我需要将其转换为浮点数,我尝试做的是:
NSData *payload <-- this contains the bytes in the "range" defined after
[payload getBytes:&bytes range:range];
float f;
int16_t bytes = OSSwapBigToHostInt16(bytes);
memcpy(&f, &bytes, 2);
NSLog(@"Value found: %f", f);
但我总是得到 0.0000 的值。
谢谢。
【问题讨论】:
-
你的标题是 Swift,但标签和代码是 Objective-C。
标签: objective-c floating-point type-conversion byte