+ (NSString *)getCheckSum:(NSString *)dataStr{
NSData *byteStr = [self convertHexStrToData:dataStr];
int length = (int)byteStr.length;
// NSData *data = [self hexToBytes:byteStr];
Byte *bytes = (unsigned char *)[byteStr bytes];
Byte sum = 0;
for (int i = 0; i<length; i++) {
sum += bytes[i];
}
int sumT = sum;
int at = 256 - sumT;
printf("校验和:%d\n",at);
printf("累加和:%d\n",sumT);
if (at == 256) {
at = 0;
}
NSString *str = [NSString stringWithFormat:@"%@",[self TenSixtoHex:sumT]];
NSString *bitStr = [self getBinaryByHex:str];
NSString *lowEightStr = [bitStr substringFromIndex:bitStr.length-8];
NSLog(@"低八位:%@",low
iOS 计算 累加校验和(CHECKSUM)的方法 低八位
最新推荐文章于 2023-10-10 10:30:00 发布