TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
decimal_to_hexadecimal.cpp
Go to the documentation of this file.
1
5
6
#include <iostream>
7
11
int
main
(
void
) {
12
int
valueToConvert = 0;
// Holds user input
13
int
hexArray[8];
// Contains hex values backwards
14
int
i = 0;
// counter
15
char
HexValues[] =
"0123456789ABCDEF"
;
16
17
std::cout <<
"Enter a Decimal Value"
18
<< std::endl;
// Displays request to stdout
19
std::cin >>
20
valueToConvert;
// Stores value into valueToConvert via user input
21
22
while
(valueToConvert > 15) {
// Dec to Hex Algorithm
23
hexArray[i++] = valueToConvert % 16;
// Gets remainder
24
valueToConvert /= 16;
25
// valueToConvert >>= 4; // This will divide by 2^4=16 and is faster
26
}
27
hexArray[i] = valueToConvert;
// Gets last value
28
29
std::cout <<
"Hex Value: "
;
30
while
(i >= 0) std::cout << HexValues[hexArray[i--]];
31
32
std::cout << std::endl;
33
return
0;
34
}
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
others
decimal_to_hexadecimal.cpp
Generated by
1.18.0