diff --git a/Classes/objc/BabyToy.h b/Classes/objc/BabyToy.h index bf2c92c..5b696ed 100644 --- a/Classes/objc/BabyToy.h +++ b/Classes/objc/BabyToy.h @@ -31,4 +31,8 @@ //根据UUIDString查找CBCharacteristic +(CBCharacteristic *)findCharacteristicFormServices:(NSMutableArray *)services UUIDString:(NSString *)UUIDString; +//BCD转十进制 ++(NSInteger)BCDToInt:(Byte)bcd; +//十进制转bcd ++(Byte)intToBCD:(NSInteger)i; @end diff --git a/Classes/objc/BabyToy.m b/Classes/objc/BabyToy.m index 7a3ce0e..ea0b5d1 100644 --- a/Classes/objc/BabyToy.m +++ b/Classes/objc/BabyToy.m @@ -86,6 +86,28 @@ + (CBCharacteristic *)findCharacteristicFormServices:(NSMutableArray *)services return nil; } + +/*** + 十进制转bcd + ****/ + + ++(Byte)intToBCD:(NSInteger)i{ + + return (((i / 10) << 4) + ((i % 10) & 0x0f)); + +} + +/*** + BCD转十进制 + ****/ + ++(NSInteger)BCDToInt:(Byte)bcd{ + + return (0xff & (bcd >> 4)) * 10 + (0xf & bcd); + +} + @end