将十进制转化为十六进制

#include<iostream>

#include<string>

using namespace std;



int main()

{

    const string hexdigits="0123456789ABCDEF";

    cout<<"Enter a series of numbers between 0 and 15"<<" separates by spaces ,Hit ENTR when finished:"<<endl;

    string result;

    string::size_type n;

    while(cin>>n)

    {

        if(n<hexdigits.size())

            result+=hexdigits[n];

        cout<<"Yours hex number is:"<<result<<endl;

    }

    return 0;

}

运行结果:

将十进制转化为十六进制

你可能感兴趣的:(十六进制)