1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
// Dec to Hex.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string r[256][2];
string Hex[16] = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
int x = 0;
for (int z = 0; z < 256; z++)
{
x = z%16;
r[z][1] = Hex[x];
x = z/16;
r[z][0] = Hex[x];
}
do
{
cout << "Please enter a decimal number ( 0 to 255 )\n";
cin >> x;
if ( x<0||x>255)
break;
cout << "The hex value for " << x << " is " << r[x][0] << r[x][1]<< "\n\n";
} while ( x <= 255 );
system("pause");
}
|