昨天Jarret Hardie(谢谢!)发布了这段代码,用于将NSinteget转换为二进制,它可以完美地工作,但我需要8位格式的:
感谢!!!!!
4 -> 00000100
有什么想法修改这个代码吗?
// Original author Adam Rosenfield... SO Question 655792
NSInteger theNumber = 56;
NSMutableString *str = [NSMutableString string];
for(NSInteger numberCopy = theNumber; numberCopy > 0; numberCopy >>= 1)
{
// Prepend "0" or "1", depending on the bit
[str insertString:((numberCopy & 1) ? @"1" : @"0") atIndex:0];
}
NSLog(@"Binary version: %@", str);
感谢!!!!!