1、#include #include #include #include #include using namespace std;string itos(int n){ ostringstream o; o << n; return o.str();}string ctos(char n){ ostringstream o; o << n; return o.str();}//采用移位运算,每四位转换为一个十六进制数void invert_1(vector
2、 &v1, int n){ int bytenum = sizeof(int); int m = 0; for(int i = 2*bytenum-1; i!=-1; --i) { m = n; m = (m >> i*4) & ~(~0 << 4); if(m>=0 && m<=9) v1.push_back(itos(m)); else v1.push_back(ctos(char(m+55))); }}//用16去除输入的十进制数void invert_2(
3、vector &v2, int n){ int shang = 0; //商 int yushu = 0; //余数 int value = 1; //权值 while(value <= n) { value = value * 16; yushu = n % value; shang = yushu * 16 / value; if(shang>=0 && shang<=9) v2.push_back(itos(shang)); else v2.push
4、_back(ctos(char(shang+55))); } reverse(v2.begin(),v2.end()); //将向量中的元素倒置}void print(vector &v){ bool first = true; //判断0要不要输出 cout << "the result is: "; for(vector::size_type it = 0; it != v.size(); ++it) { if(v[it]=="0" && first == true) conti