0
詮釋
我們的自定義智能路由器是給我NSData
響應十六進制轉換NSData的在目標C
< 800c01ff 0001ffff ffff29ff>
這裏,800c
是我的DeviceID。如何將其轉換爲int
?
deviceId = 32780;
當我發送命令給路由器構建我喜歡它,從Larme的評論採取
Byte mqttData[12];
mqttData[0] =[[NSNumber numberWithUnsignedChar:(deviceID >> 8) & 0xFF] intValue];
//mqttData[0]=128 or 80 in Hex
mqttData[1] =[[NSNumber numberWithUnsignedChar:deviceID & 0xFF] intValue];
//mqttData[1]=12 or 'C' in Hex
return [NSData dataWithBytes:mqttData length:sizeof(mqttData)];
使用'NSData * deviceIDData = [theDataResponse subdataWithRange:NSMakeRange(0,2)],int deviceId; [deviceIDData getBytes:&deviceId length:sizeof(int)];'? – Larme
爲什麼'NSNumber'涉及到所有? – Droppy
@Lamre DEVICEID:5508224.但它是32780 –