/**
十进制正数转二进制
@param number 十进制正数
@return 二进制字符串
*/
- (NSString *)binaryNumberStringFromIntegerNumber:(NSUInteger )number{
NSMutableString *resultStr = [NSMutableString string];
if (number == 1 || number == 0) {
return [NSString stringWithFormat:@"%ld",number];
}
//递归、拼接
while (number/2) {
NSUInteger singleNumber = number % 2;
NSString *singleStr = [NSString stringWithFormat:@"%ld",singleNumber];
[resultStr insertString:singleStr atIndex:0];
number = number / 2;
//最后一位需判断、其实就是最高位1
if (number / 2 == 0) {
NSString *devStr = [NSString stringWithFormat:@"%ld",number];
[resultStr insertString:devStr atIndex:0];
}
}
return resultStr;
}