2016-10-14 16:12:54 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2018-10-23 20:17:43 +08:00
|
|
|
int main(void){
|
2016-10-14 16:12:54 +08:00
|
|
|
int valueToConvert = 0; //Holds user input
|
|
|
|
int hexArray[8]; //Contains hex values backwards
|
|
|
|
int i = 0; //counter
|
2018-10-23 20:17:43 +08:00
|
|
|
char HexValues[] = "0123456789ABCDEF";
|
2016-10-14 16:12:54 +08:00
|
|
|
|
|
|
|
cout << "Enter a Decimal Value" << endl; //Displays request to stdout
|
|
|
|
cin >> valueToConvert; //Stores value into valueToConvert via user input
|
|
|
|
|
2018-10-23 20:17:43 +08:00
|
|
|
while (valueToConvert > 15){ //Dec to Hex Algorithm
|
|
|
|
hexArray[i++] = valueToConvert % 16; //Gets remainder
|
|
|
|
valueToConvert /= 16;
|
2016-10-14 16:12:54 +08:00
|
|
|
}
|
2018-10-23 20:17:43 +08:00
|
|
|
hexArray[i] = valueToConvert; //Gets last value
|
|
|
|
|
2016-10-14 16:12:54 +08:00
|
|
|
cout << "Hex Value: ";
|
2018-10-23 20:17:43 +08:00
|
|
|
while (i >= 0)
|
|
|
|
cout<<HexValues[hexArray[i--]];
|
|
|
|
|
2016-10-14 16:12:54 +08:00
|
|
|
cout << endl;
|
2018-10-23 20:17:43 +08:00
|
|
|
return 0;
|
2016-10-14 16:12:54 +08:00
|
|
|
}
|