开发者

how to convert nsstring to Binary and that Binary to Hexadecimal

开发者 https://www.devze.com 2023-03-09 10:29 出处:网络
I am having multiple values in the string Here is the example of my string str1 = @\"20AB\" str2 = @\"298C30:2FC0A0:2FC09C:FFFFFFFF:2FDFCD34:00\"

I am having multiple values in the string Here is the example of my string

str1 = @"20AB"

str2 = @"298C30:2FC0A0:2FC09C:FFFFFFFF:2FDFCD34:00"

str3 = @"4ffd565372df51089f2c824526f4f95a13daa867"

str4 = hexa(binary(str1 + str2 +str3))

i.e. I need to convert the strings to Binary and then to Hexa开发者_如何转开发 decimal and then concat all 3 strings in a single string.

Please help me out how to do so.

thanks in advance


I don't know much of Obj-C or the iPhone SDK, but in C your solution would be along these lines:

  • use strtol() to convert the strings into numbers (check the pointer returned through the second parameter to that function for '\0' to tell apart whether you reached end-of-string or merely the next ':' delimiter);
  • use sprintf() with the %x conversion specifier to turn the numbers into a string again.

Unfortunately your question is not precise enough for a more precise answer.


you can use NSScanner for converting to HEx and Bytes to read the binary data...

0

精彩评论

暂无评论...
验证码 换一张
取 消