Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要转换一些具有小数内容的字符串。我希望这些内容在一个字符串中,以十六进制格式...
我该怎么做?
我尝试使用 NSScanner 但这种方法似乎有点大,只是进行 dec-hex 计算?
感谢您的回答!
如果您知道您的字符串只包含一个有效的十进制数,那么最简单的方法是:
NSString *dec = @"254"; NSString *hex = [NSString stringWithFormat:@"0x%lX", (unsigned long)[dec integerValue]]; NSLog(@"%@", hex);