How can I convert hex number to integers and strings in Objective C?

前端 未结 2 1922
情深已故
情深已故 2020-12-20 23:10

Given the example of an array like this:

idx = [ 0xe, 0x3,  0x6, 0x8, 0x2 ]

I want to get an integer and string representation of each of

相关标签:
2条回答
  • 2020-12-20 23:46

    Once you have an NSString you can just use the methods in that class, like intValue or longValue or floatValue

    0 讨论(0)
  • 2020-12-21 00:00

    To get the decimal and hexadecimal equivalents, you would do:

    int number = 0xe; // or 0x3, 0x6, 0x8, 0x2
    
    NSString * decimalString = [NSString stringWithFormat:@"%d", number];
    NSString * hexString = [NSString stringWithFormat:@"%x", number];
    
    0 讨论(0)
提交回复
热议问题