Write a c or c++ program that convert octal number into binary number and print the binary equivalent

It is simple c or c++ program that convert octal base number into equivalent binary numbers.
In this resource I will explain the procedure to convert octal number to binary number with the help of screen shoots.
At first know about the what is the octal number and binary number.Octal number is the number which represented in 8 base. Means that the number represented in 8 base is called octal number.
In octal number each digits does not exceed the value of 8.
That is the valid digits in octal number system is
1, 2, 3, 4, 5, 6, 7.  If we want to write number 9 then in octal it is 11. 
Just like 558is octal number. Binary number is the number which is represented in base 2.
In binary number system only two digits is valid, which is 0, 1.
binary number is 10012
If we talk about the simple conversion of octal to binary then replace each octal digits to equivalent binary digit. means that the if we want to convert octal number 558 to binary then
i.e. 558=1011012If we talk about the programming aspect to convert octal to binary number then we need to follow specific procedure.
Octal number first convert into decimal number after that convert decimal number to binary number.Lets see the code in c or c++ programming language.

/*By bharat kumar dhakerwww.computersciencearticle.in*/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int power_Calulate(int,int);
int Octal_to_DecimalConvert(int);
void main()
int number;printf("enter number in 8 basen");
int decimal=Octal_to_DecimalConvert(number);
char binary[7];int i; 
for( i = 6; i >= 0; i--)   
if( (1 << i) & decimal)    
binary[6 - i] = '1';
binary[6 - i] = '0';   
binary[7] = 0;
printf("After convert binary value isn %s",binary);
int Octal_to_DecimalConvert(int number)
int resultDec = 0; 
int n = 0;
int numberTemp = 0;
if (number < 10)        
return number; 
while (number / 10) 
numberTemp = number % 10;  
resultDec  = (numberTemp * power_Calulate(8,n));
number /= 10;
resultDec  = (number *power_Calulate(8,n));
return resultDec;
int power_Calulate(int base, int power)
int i,temp =1; 
if(power==0)  return(1); 
if(power==1)  return(base); 
temp = temp*base;  

Source Code: Octal To Binary 

Lets take example to convert.
We want to convert 118 into binary.
Then output is as shown in figure.

octal to binary convert

output of octal to binary convert

One Response
  1. September 3, 2013