how to convert nsstring to Binary and that Binary to Hexadecimal

≯℡__Kan透↙ 提交于 2019-12-11 04:58:56

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6175833/how-to-convert-nsstring-to-binary-and-that-binary-to-hexadecimal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!