I have a problem, I need to convert char [] to String, hexadecimal
Example
Nsstring * result; char[4]={0x01,0x02,0x03,0x04}; /// convert -- char[] -> Nsstring in Hex format Nslog(@"%@",result);
Expected Result: "01020304"
thanks
try the following:
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 formatting "% 02x" will display a single character in the form of two digits of the zero igniter. Just loop your array and build a line with them.