Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
decimal_to_hexadecimal.cpp File Reference

Convert decimal number to hexadecimal representation. More...

#include <iostream>
Include dependency graph for decimal_to_hexadecimal.cpp:

Functions

int main (void)
 

Detailed Description

Convert decimal number to hexadecimal representation.

Function Documentation

◆ main()

int main ( void )

Main program

11 {
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
33 return 0;
34}
T endl(T... args)
Here is the call graph for this function: