如何将一个十六进制字符串转换为ascii,包括空值 [英] how to convert a string of hex chars to ascii, including nulls

查看:246
本文介绍了如何将一个十六进制字符串转换为ascii,包括空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一串十六进制字符(2个十六进制字符= 1个字节)转换为ASCII。十六进制字符也包括零(0x00),我想包含在ASCII字符串中。


十六进制字符串:5000005355 ....

ASCII:P< ; null>< null> SU ...


我可以做到这一点,字符串长度也包括空值但是当我连接其他字符串时,它不会显示为其部分。


I want to convert a string of hex characters (2 hex chars = 1 byte), to ASCII. Hex chars include zeros (0x00) as well, which I want to include in ASCII string.

hex string: 5000005355....
ASCII: P<null><null>SU...

I can do it and the string length also includes nulls but when I concatenate other string, it doesn''t show as its part.


展开 | 选择 | Wrap | 行号

推荐答案

在连接后放入一个断点检查变量的实际值。如果它完整但显示错误我不会感到惊讶。字符串通常不能很好地处理它们中的空值。空终止是相当标准的,所以当控件达到null时,它可能会停止查找。
Put a breakpoint in after the concatenate and check the actual value of your variable. I wouldn''t be surprises if it was complete but displaying wrong. Strings often don''t deal well with having nulls in them. Null termination is fairly standard so when a control reaches the null it may just stop looking.


如果要在套接字上发送它,为什么要将它转换为字符串?
Why would you convert it to a string if you were going to send it on a socket?


@tlhintoq


在工具提示中,它显示带有空值的字符串和hello ;最后,但是在快速观看窗口中,它只显示第一个''\ 0''之前的字符,而没有你好...
@tlhintoq
In the tooltip, it shows the string with nulls and "hello" at the end, but in ''quick watch'' window, it shows only characters before first ''\0'' and no "hello"...


这篇关于如何将一个十六进制字符串转换为ascii,包括空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆