十六进制带符号(-号)
2019-01-27 本文已影响6人
蜗牛锅
蓝牙与硬件交互的项目,遇到这样需要求,蓝牙返回的数据,带有符号 (-号)
IMG_2DF2626A 7035-1.jpeg
-
(NSString *)decimalwithFormat:(NSData *)dataV {
if (dataV == nil) {
return @"0";
}NSData *ff = [DataConvert hexStringToData:@"FFFFFFFF"];
NSInteger addupInt;
NSString *resultStr;
float addupF = 0.00;if ([[dataV subdataWithRange:NSMakeRange(0, 1)] isEqualToData:[DataConvert hexStringToData:@"ff"]]) {
addupInt = [DataConvert dataToInteger:ff] - [DataConvert dataToInteger:dataV]; addupF = (addupInt + 1) * 0.01; resultStr = [NSString stringWithFormat:@"-%.2f",addupF];
} else {
addupInt = [DataConvert dataToInteger:dataV];
addupF = addupInt * 0.01;
resultStr = [NSString stringWithFormat:@"%.2f",addupF];
}NSLog(@"格式化数据 -- %@",resultStr);
return resultStr;
}