且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将十进制转化为十六进制

更新时间:2021-10-01 04:29:31

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

运行结果:

将十进制转化为十六进制