简体   繁体   English

如何将 nsstring 转换为二进制和二进制转换为十六进制

[英]how to convert nsstring to Binary and that Binary to Hexadecimal

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))

ie I need to convert the strings to Binary and then to Hexa decimal and then concat all 3 strings in a single string.即我需要将字符串转换为二进制,然后转换为十六进制十进制,然后将所有 3 个字符串连接到一个字符串中。

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:我不太了解 Obj-C 或 iPhone SDK,但在 C 中,您的解决方案将遵循以下原则:

  • 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);使用strtol()将字符串转换为数字(检查通过第二个参数返回到 function 的指针是否为'\0'以区分您是否到达字符串结尾或仅是下一个':'分隔符);
  • use sprintf() with the %x conversion specifier to turn the numbers into a string again.使用sprintf()%x转换说明符将数字再次转换为字符串。

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...您可以使用 NSScanner 转换为 HEx 和 Bytes 来读取二进制数据...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM