i have string representing data .i need to convert those data to the hex array .By using the hex array data i can pass it to the CRC for writing to the peripheral
M
A. The hexadecimal format is simply another representation of the same data.
B. You do not convert them into hex array. Every character has a number. For example in ASCII and UTF-8 the A
has the number 65 (decimal representation). This is 0x41 in hex representation.
'A' (ASCII) == 65 == 0x41.
A hex number has the the digits 0
-9
, a
-f
, wherein a
has the value of 10, b
the value of 11 … It is converter into decimal representation by multiplying the upper digit by 16 and adding the lower digit. (0x41: 4 x 16 + 1 = 65.)
Please read and understand this: http://en.wikipedia.org/wiki/Hexadecimal
C. To convert a string into its number, you have to know, which code you want to apply. Probably you want to use UTF-8.
NSString *text = @"helloworld123123989128739";
NSUInteger length = [text lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
char data[length];
[text getCString:data maxLength:length usingEncoding:NSUTF8StringEncoding];
// Here we go