I have a problem I need to convert char [] to String, hexadecimal format
Example
Nsstring * result;
char[4]={0x01,0x02,0x03,0x04};
/// convert -- char[] -> Nsstring in Hex format
Nslog(@"%@",result);
expected output: "01020304"
Thanks
try this:
NSMutableString * result = [[NSMutableString alloc] init]; char cstring[4]={0x01,0x02,0x03,0x04}; /// convert -- char[] -> Nsstring in Hex format int i; for (i=0; i<4; i++) { [result appendString:[NSString stringWithFormat:@"%02x",cstring[i]]]; } NSLog(@"%@",result); [result release];
The formatter "%02x" will display an individual character as 2 digits of zero-padded hex. Simply loop though your array and build the string with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With