将十进制转化为十六进制

#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;
}

运行结果:

posted @ 2014-08-02 22:47  Jessica程序猿  阅读(345)  评论(0编辑  收藏  举报