To convert a numbers into its equivalent we divide the given number with its base for example to convert into Octal divide with 8 and for Hexadecimal divide it with 16. For Hexadecimal Further more condition is applied which show the alphabet.
Source Code
#include<iostream> #include<conio.h> using namespace std; int main() { int num; cout<<"\n\n\n ************** NUMBER CONVERSION ************** \n\n\n"; cout<<" \n Enter Number = "; cin>>num; int digit=num; int n=num; cout<<" \n \n In Binary = "; while(num>0) { int remminder; remminder=num%2; cout<<remminder; num=num/2; } cout<<" \n \n In Octal = "; while(digit>0) { int r; r=digit%8; cout<<r; digit=digit/8; } cout<<" \n \n In Hexa Decimal= "; while(n>0) { int remminderm; remminderm=n%16; if(remminderm<9) { cout<<remminderm; } else if(remminderm==10) { cout<<"A"; } else if(remminderm==11) { cout<<" B "; } else if(remminderm==12) { cout<<" C "; } else if(remminderm==13) { cout<<" D "; } else if(remminderm==14) { cout<< " E "; } else if(remminderm==15) { cout<< " F "; } n=n/16; } return 0; }
0 comments:
Post a Comment