将 NSString 的内容转换为它们代表的字节
可能的重复:
NSString(十六进制)到字节
我目前在尝试转换 NSString
到一个字节。
我的程序接收一个字符串,例如将 CC
转换为字节 0xCC
我知道您可以将 NSString
转换为其十六进制表示形式,但这不是这不是我需要的,因为它使用字符串编码 - 我的 CC
将变成 0x63
。
据我了解,我需要将 NSString
(或 char
)转换为原始字节,以便稍后可以将其转换为十进制,但我真的很困惑如何去做。
Possible Duplicate:
NSString (hex) to bytes
I'm currently stuck trying to convert the contents of a NSString
to a byte.
My program receives a string, for example CC
to a byte 0xCC
I understand that you can convert an NSString
to its hex representation, but this isn't what I need, as that uses the string encoding -- my CC
would turn out as 0x63
.
From what I understand, I need to cast the NSString
(or char
) to a raw byte, so that I can then later on convert it to a decimal but i'm getting really confused on how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能 100% 确定这是否是您的意思,但
会创建一个字节数组。
Not 100% sure if this is what you mean but
would create a byte array.