标签:-- maker ret intvalue ring 进制 nsstring hang iso
+ (NSString*)changeToBinarySystem:(NSString*)number {
NSInteger num = [number intValue];
NSInteger remainder = 0;
NSInteger divisor = 0;
NSString *prepare=@"";
while (num!=0) {
remainder = num%2;
divisor = num/2;
num = divisor;
prepare = [prepare stringByAppendingFormat:@"%ld",remainder];
}
NSString *result=@"";
int strLenht = prepare.length%4;
if (strLenht==1) {
result = @"000";
}else if (strLenht==2) {
result = @"00";
}else if (strLenht==3) {
result = @"0";
}
for (NSInteger i = prepare.length - 1; i >= 0;i--) {
result = [result stringByAppendingFormat:@"%@",[prepare substringWithRange:NSMakeRange(i, 1)]];
}
return result;
}
标签:-- maker ret intvalue ring 进制 nsstring hang iso
原文地址:http://www.cnblogs.com/tony0571/p/6132623.html