Last active
December 23, 2015 14:29
-
-
Save Zulqurnain/18a1eb80cc4068309c2c to your computer and use it in GitHub Desktop.
C++ Code to convert Decimal To Hexa !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream.h> | |
| int main(){ | |
| int Deci,i=0; | |
| int THex[100]; // Reason To Use : We Need A,B,C,D,E character To Represent Value of HEX | |
| char Hex[100]; // Stores HEX | |
| cout<<"Enter Decimal Number :=:"; cin>>Deci; | |
| int Current_r=Deci , Current_q=Deci; | |
| while(Current_q>=16){ // getting all remainders in array Reversed | |
| Current_q/=16; | |
| Current_r =Deci % 16; | |
| THex[i]=(Current_r); | |
| i++ , Deci=Current_q; | |
| } | |
| THex[i]= Current_q; | |
| int j=0; // Value of Starting | |
| while(i>=0){ | |
| Hex[j] = THex[i] + '0'; // In Characters , Character = Number + 48; | |
| if(THex[i] == 10){ | |
| Hex[j]='A'; | |
| } | |
| else if(THex[i] == 11){ | |
| Hex[j]='B'; | |
| } | |
| else if(THex[i] == 12){ | |
| Hex[j]='C'; | |
| } | |
| else if(THex[i] == 13){ | |
| Hex[j]='D'; | |
| } | |
| else if(THex[i] == 14){ | |
| Hex[j]='E'; | |
| } | |
| else if(THex[i] == 15){ | |
| Hex[j]='F'; | |
| } | |
| j++; | |
| i--; | |
| } | |
| Hex[j]='\0'; | |
| cout<<"Hex :=:"<<Hex; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment