Saturday, November 30, 2013

Decimal to Hexa Decimal and Octal Converter

It is the simplest method to convert a decimal number into Hexa Decimal or Octal number...
It just require two keywords...
one is "hex" (obviously without quotes :p) and the other is "oct".

Here how it works:

Output

And here is the code to make it work...


// www.cppfuzz.com (Ahmad Mukhtar)
/*
  ______ .______   .______    _______  __    __   ________   ________  
 /      ||   _  \  |   _  \  |   ____||  |  |  | |       /  |       /  
|  ,----'|  |_)  | |  |_)  | |  |__   |  |  |  | `---/  /   `---/  /   
|  |     |   ___/  |   ___/  |   __|  |  |  |  |    /  /       /  /    
|  `----.|  |      |  |      |  |     |  `--'  |   /  /----.  /  /----.
 \______|| _|      | _|      |__|      \______/   /________| /________|
                                                                       
*/
#include <iostream>
using namespace std;
void main()

{
 int dec_number;
 cout << "Enter a decimal number: ";
 cin >> dec_number; // getting decimal number from user.
 cout << endl;
 cout << "Number in Hexa Decimal: " << hex << uppercase << dec_number << endl;

 /* In the above line i used hex for conversion, uppercase for uppercase alphabets in hexa decimal numbers and then
 printed it on the screen using cout */
 
 cout << "Number in Octal: " << oct << dec_number << endl; // used oct for octal conversion.
}

Widgets

 

Copyright @ 2014 CPP Fuzz.