mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-01 09:43:06 +08:00
Moved programs to appropriate directories
This commit is contained in:
26
Others/Decimal To Hexadecimal .cpp
Normal file
26
Others/Decimal To Hexadecimal .cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(void){
|
||||
int valueToConvert = 0; //Holds user input
|
||||
int hexArray[8]; //Contains hex values backwards
|
||||
int i = 0; //counter
|
||||
char HexValues[] = "0123456789ABCDEF";
|
||||
|
||||
cout << "Enter a Decimal Value" << endl; //Displays request to stdout
|
||||
cin >> valueToConvert; //Stores value into valueToConvert via user input
|
||||
|
||||
while (valueToConvert > 15){ //Dec to Hex Algorithm
|
||||
hexArray[i++] = valueToConvert % 16; //Gets remainder
|
||||
valueToConvert /= 16;
|
||||
}
|
||||
hexArray[i] = valueToConvert; //Gets last value
|
||||
|
||||
cout << "Hex Value: ";
|
||||
while (i >= 0)
|
||||
cout<<HexValues[hexArray[i--]];
|
||||
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user