#include iostream
Using namespace STD
#include iomanip
//将单个字符转换为十六进制表示法
/*
314D63 '==' 1Mc '
流程:
3' (0x33)==0x3,
1' (0x31)==0x1,
4’(0 x 34)==0 x 4,
D' (0x44)==0xD,
6' (0x36)==0x6,
3' (0x33)==0x3,
*/
unsigned charchar 2 hex(unsigned char uctemp)
{
unsigned char ucResult=0;
If(ucTemp='0' ucTemp='9 ')
{
UC result=UC temp-' 0 ';
}
Else if(ucTemp='a' ucTemp='f ')
{
UC result=UC temp-' a ' 10;
}
Else if(ucTemp='A' ucTemp='F ')
{
UC result=UC temp-' A ' 10;
}
//hex仅适用于整数
cout _ _ function _ _ ' ' hex(unsigned int)uctemp ' '
unsigned int(hex)ucResult endl;
Return ucResult
}
//' 314 d63 '=' 1Mc '
//' 31323361627 a '=' 123 abz '
//十六进制纯文本字符串“314D63”,hex:{33 31 34 44 36 33==十六进制{31 4D 63},字符串“1Mc”
string hextostring(string hexstring)
{
字串街;
I()
{
Return strRet
}
unsigned char ucResult=0;
for(int I=0;I();I=2)
{
//两个位构成一个字节
/*
3’(0 x 33)==0 x 3,‘1’(0 x 31)==0 x 1,==0x31配置
*/
UC result=char 2 hex(hexstring[I])* 0 x 10 char 2 hex(hexstring[I 1]);
cout _ _ function _ _ ' UC result hex ' hex(unsigned int)UC result endl;
StrRet=ucResult//十六进制数的组合为{0x31,0x4D,0x63}==结果为' 1Mc '
}
Return strRet
}
Int main()
{
//纯文本字符串“314D63”,hex:{33 31 34 44 36 33==十六进制数字{31 4D 63},字符串“1Mc”
String hexStr1=' 314D63
string ascii str 1=hext ostring(hexstr 1);
cout ' ascii str 1==' ascii str 1 endl endl;
//' 31323361627 a '=' 123 abz '
String hexStr2=' 31323361627A///' 00030020002 DB ';//' 31323361627 A ';
string ascii str 2=hext ostring(hexstr 2);
cout ' asciistr 2==' asciistr 2 endl;
return 0;
}
/*
Char2Hex 33 3
Char2Hex 31 1
HexToString ucResult hex 31
Char2Hex 34 4
Char2Hex 44 d
HexToString ucResult hex 4d
Char2Hex 36 6
Char2Hex 33 3
HexToString ucResult hex 63
AsciiStr1==1Mc
Char2Hex 33 3
Char2Hex 31 1
HexToString ucResult hex 31
Char2Hex 33 3
Char2Hex 32 2
HexToString ucResult hex 32
Char2Hex 33 3
Char2Hex 33 3
HexToString ucResult hex 33
Char2Hex 36 6
Char2Hex 31 1
HexToString ucResult hex 61
Char2Hex 36 6
Char2Hex 32 2
HexToString ucResult hex 62
Char2Hex 37 7
Char2Hex 41 a
HexToString ucResult hex 7a
AsciiStr2==123abz
*/
1.《C++ 16进制明文字符串"314D63"==>转16进制「0x31,0x4D,0x63」》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。
2.《C++ 16进制明文字符串"314D63"==>转16进制「0x31,0x4D,0x63」》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。
3.文章转载时请保留本站内容来源地址,https://www.lu-xu.com/gl/3260871.html