Introduction
Control Statement
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
- Program to find reverse of the number
- Program to Check Armstrong Number
Function
- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle
Array
Pointer
OOPS
No Examples found for this topic - CodeHelpPro
Program to convert Octal to Binary Number
In this example, We will learn how to convert octal number to binary number.
To understand this example, You must have knowledge in following topics
#include <iostream>
#include <cmath>
using namespace std;
long long convertOctalToBinary(int);
int main()
{
int octalNumber;
cout << "Enter an octal number: ";
cin >> octalNumber;
cout << octalNumber << " in octal = " << convertOctalToBinary(octalNumber) << " in binary";
return 0;
}
long long convertOctalToBinary(int octalNumber)
{
int decimalNumber = 0, i = 0;
long long binaryNumber = 0;
while(octalNumber != 0)
{
decimalNumber += (octalNumber%10) * pow(8,i);
++i;
octalNumber/=10;
}
i = 1;
while (decimalNumber != 0)
{
binaryNumber += (decimalNumber % 2) * i;
decimalNumber /= 2;
i *= 10;
}
return binaryNumber;
}
The output of above program is
Enter an octal number: 5
5 in octal = 101 in binary
In the above example, We have created one function convertOctalToBinary() which converts the octal number to the binary number.
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments