#include <iostream>
#include <string>
#include <stdint.h>
using namespace std;
string BinToHex(const string &strBin, bool bIsUpper = false)
{
string strHex;
strHex.resize(strBin.size() * 2);
for (size_t i = 0; i < strBin.size(); i++)
{
uint8_t cTemp = strBin[i];
for (size_t j = 0; j < 2; j++)
{
uint8_t cCur = (cTemp & 0x0f);
if (cCur < 10)
{
cCur += '0';
}
else
{
cCur += ((bIsUpper ? 'A' : 'a') - 10);
}
strHex[2 * i + 1 - j] = cCur;
cTemp >>= 4;
}
}
return strHex;
}
int main()
{
string strBin;
cout << "二进制输入:";
cin >> strBin;
string strHex = BinToHex(strBin);
cout << "十六进制数是:"<< strHex << endl;
return 0;
}
问题解决的话,请点下采纳