Skip to content

Instantly share code, notes, and snippets.

@javiermontenegro
Created November 30, 2019 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javiermontenegro/150f7c26412736192c3a111dcb039925 to your computer and use it in GitHub Desktop.
Save javiermontenegro/150f7c26412736192c3a111dcb039925 to your computer and use it in GitHub Desktop.
This gist is a example of how to convert decimal to hexadecimal in C++
/*********************************************************************
* Filename: Cpp_Decimal.To.Hexadecimal.cpp
* Author: Javier Montenegro (javiermontenegro.github.io)
* Copyright: @2019
* Details: this gist is a example of how to convert decimal to hexadecimal in C++
*********************************************************************/
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
int number = 0;
int i = 0;
int hexArray[8];
char HexValues[] = "0123456789ABCDEF";
cout << "Enter a number:";
cin >> number;
while (number > 15){
hexArray[i++] = number % 16;
number /= 16;
}//End while
hexArray[i] = number;
cout << "The binary is :";
while (i >= 0){
cout<<HexValues[hexArray[i--]];
}//End while
cout << endl;
return 0;
}//End main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment