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

{
int valueToConvert = 0; // Holds user input
int hexArray[8]; // Contains hex values backwards
int i = 0; // counter
char HexValues[] = "0123456789ABCDEF";
std::cout << "Enter a Decimal Value"
<< std::endl; // Displays request to stdout
std::cin >>
valueToConvert; // Stores value into valueToConvert via user input
while (valueToConvert > 15) { // Dec to Hex Algorithm
hexArray[i++] = valueToConvert % 16; // Gets remainder
valueToConvert /= 16;
// valueToConvert >>= 4; // This will divide by 2^4=16 and is faster
}
hexArray[i] = valueToConvert; // Gets last value
std::cout << "Hex Value: ";
while (i >= 0) std::cout << HexValues[hexArray[i--]];
std::cout << std::endl;
return 0;
}
std::cin
std::cout
std::endl
T endl(T... args)
Here is the call graph for this function: