Binary

Write a program that continues to ask the user to enter any decimal number and calculate it’s binary,octal and hexadecimal equivalent.

Questions by dhairaybablani

Showing Answers 1 - 6 of 6 Answers

rohit suri

  • Sep 11th, 2014
 

Code
  1.  

  2. int binary_function(int num)

  3. {

  4.    if(num==1)

  5.       return 1;

  6.   else

  7.     return binary_function(num/2)*10+(num%2);

  8. }

  9.  

Badugu

  • Mar 11th, 2015
 

Please try following:

Code
  1. #include<iostream>

  2. #include<fstream>

  3. #include <bitset>

  4.  

  5. using namespace std;

  6.  

  7. int main()

  8. {

  9.     int i,j;

  10.     cout<<"Enter a decimal Number:";

  11.     while (cin>>i) {

  12.                  

  13.           cout<<"Hexa Decimal:"<<std::hex<<i<<"     Octal:"<<std::oct<<i<<endl;

  14.           std::bitset<8> x(i);

  15.           cout<<"Binary:"<<x<<endl;

  16.           cout<<"Enter a decimal Number:";

  17.           }

  18.          

  19.           return 0;

  20.           }

  21.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions