博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++汉字与十六进制相互转换
阅读量:2090 次
发布时间:2019-04-29

本文共 1073 字,大约阅读时间需要 3 分钟。

在项目中需要使用C++将汉字与十六进制互相转换,举例:

在UE上打“中国人”得到十六进制是“D6D0B9FAC8CB0D0A”,这是如何转换的,以及如何将char str[]=”D6D0B9FAC8CB0D0A”; 换成汉字放在 char[10]={0}这个数组中呢?

#include
#include
#include
#include
using namespace std;unsigned char ch2hex(char ch) { static const char *hex="0123456789ABCDEF"; for(unsigned char i=0;i!=16;++i) if(ch==hex[i]) return i; return 0; }char* solve(char *dest,const char *src) { int i=0; int cnt=0; unsigned char*d=(unsigned char*)dest; while(*src) { if(i&1) { d[cnt++]|=ch2hex(*src); } else { d[cnt]=ch2hex(*src)<<4; } src++; i++; } return dest; }string tohex(const string& str) { string ret; static const char *hex="0123456789ABCDEF"; for(int i=0;i!=str.size();++i) { ret.push_back(hex[(str[i]>>4)&0xf]); ret.push_back( hex[str[i]&0xf]); } return ret; }int main() { cout<
<

参考文献:

转载地址:http://diqqf.baihongyu.com/

你可能感兴趣的文章
Leetcode Go 《精选TOP面试题》20200628 69.x的平方根
查看>>
leetcode 130. Surrounded Regions
查看>>
【Python】详解Python多线程Selenium跨浏览器测试
查看>>
Jmeter之参数化
查看>>
Shell 和Python的区别。
查看>>
【JMeter】1.9上考试jmeter测试调试
查看>>
【虫师】【selenium】参数化
查看>>
【Python练习】文件引用用户名密码登录系统
查看>>
学习网站汇总
查看>>
【Loadrunner】性能测试报告实战
查看>>
【自动化测试】自动化测试需要了解的的一些事情。
查看>>
【selenium】selenium ide的安装过程
查看>>
【手机自动化测试】monkey测试
查看>>
【英语】软件开发常用英语词汇
查看>>
Fiddler 抓包工具总结
查看>>
【雅思】雅思需要购买和准备的学习资料
查看>>
【雅思】雅思写作作业(1)
查看>>
【雅思】【大作文】【审题作业】关于同不同意的审题作业(重点)
查看>>
【Loadrunner】通过loadrunner录制时候有事件但是白页无法出来登录页怎么办?
查看>>
【English】【托业】【四六级】写译高频词汇
查看>>