You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB>16<31><36><EFBFBD>ƵĻҽ<C4BB>תΪһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD>ֵ
|
|
|
|
|
int toDec(char a, char b) {
|
|
|
|
|
int res = 0;
|
|
|
|
|
if (a >= 'A' && a <= 'F')
|
|
|
|
|
res += (a - 'A' + 10) * 16;
|
|
|
|
|
else
|
|
|
|
|
res += (a - '0') * 16;
|
|
|
|
|
|
|
|
|
|
if (b >= 'A' && b <= 'F')
|
|
|
|
|
res += b - 'A' + 10;
|
|
|
|
|
else
|
|
|
|
|
res += b - '0';
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><>һ<EFBFBD><D2BB>ʮ<EFBFBD><CAAE><EFBFBD>ƵĻҽ<C4BB>ֵ[0,255]ת<><D7AA><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>[0,FF]
|
|
|
|
|
string toHex(int x) {
|
|
|
|
|
int a = x % 16; // 0 ~ 15
|
|
|
|
|
int b = x / 16; //
|
|
|
|
|
char c1;
|
|
|
|
|
if (a >= 10)
|
|
|
|
|
c1 = 'A' + a - 10;
|
|
|
|
|
else
|
|
|
|
|
c1 = '0' + a;
|
|
|
|
|
char c2;
|
|
|
|
|
if (b >= 10)
|
|
|
|
|
c2 = 'A' + b - 10;
|
|
|
|
|
else
|
|
|
|
|
c2 = '0' + b;
|
|
|
|
|
string res;
|
|
|
|
|
res.push_back(c2);
|
|
|
|
|
res.push_back(c1);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
cout << toDec('A', 'B') << endl; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>171<37><31><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>10*16+11=171
|
|
|
|
|
cout << toDec('1', '2') << endl; //18
|
|
|
|
|
cout << toDec('0', '2') << endl; //2
|
|
|
|
|
|
|
|
|
|
cout << toHex(171) << endl;
|
|
|
|
|
cout << toHex(18) << endl;
|
|
|
|
|
cout << toHex(2) << endl;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|