Hi. I am trying to iterate through the ASCII codes (just as an experiment) and not sure how I can express the code in the string literal.
For example, within the for loop, with i going from 1 to 255, I want to print:
and that is where I am stuck.
For instance, if i = 65 (which is ASCII character "A") then the hex value is 41.
Literally, the string would be
but since I am using the variable i to iterate, how do I 1) convert the decimal to hex and 2) express that inside the NSLog string literal?
I Googled around and found two class methods for the dec/hex conversion but the above is still unclear. I suspect I need to cast the string to a value and then also somehow "escape" that value into the string literal.
Thanks.
For example, within the for loop, with i going from 1 to 255, I want to print:
Code:
NSLog(@"Character is \x..."
For instance, if i = 65 (which is ASCII character "A") then the hex value is 41.
Literally, the string would be
Code:
@"\x41"
but since I am using the variable i to iterate, how do I 1) convert the decimal to hex and 2) express that inside the NSLog string literal?
I Googled around and found two class methods for the dec/hex conversion but the above is still unclear. I suspect I need to cast the string to a value and then also somehow "escape" that value into the string literal.
Code:
NSString * decimalString = [NSString stringWithFormat:@"%d", number];
NSString * hexString = [NSString stringWithFormat:@"%x", number];