用2或3行代码将十六进制值转换为ascii [英] code in 2 or 3 lines to convert hex value to ascii

查看:89
本文介绍了用2或3行代码将十六进制值转换为ascii的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码

1)

Hi,

here is my code

1)

long crcVal=22271827222;

tempFile<<hex<<crcVal;

同一个crcVal,我想转换成ascii吗?
在这方面帮助我.

2)

same crcVal, i want to convert into ascii?
help me in this.

2)

long bufflength=1500;

tempFile<<bin<<bufflength // here it is not printing binary number ,some decimal value is printing in the file.


在这里我想将二进制格式的bufflength打印到文件中.

请在这方面帮助我

在此先感谢

Bye


here i want to print the bufflength in binary number into the file.

please help me in this regard

thanks in advance

Bye

推荐答案

您的文件流应打开以进行二进制写入.

参见 http://www.cplusplus.com/reference/iostream/fstream/fstream/ [ ^ ]

所以你应该得到这样的东西:
fstream
Your filestream should be opened for binary writing.

see http://www.cplusplus.com/reference/iostream/fstream/fstream/[^]

so you should get something like this :
fstream
filestr ("test.bin", fstream::in | fstream::out | fstream::binary);
fstream << crcVal;


http://www.dreamincode.net/forums/topic/193194-convert-hex -to-ascii/ [ ^ ]
http://stackoverflow.com/questions/8147175/how-to-convert-long-long-ascii-hex-values-into-a-string[^]
http://www.dreamincode.net/forums/topic/193194-convert-hex-to-ascii/[^]


这篇关于用2或3行代码将十六进制值转换为ascii的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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