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

| April 2, 2012 | 1 Comment
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

Category: Articles, c or c++, Practical Implementation

About the Author ()

Bharat Kumar Dhaker Founder and Editor of ComputerSciencearticle.in, He is an Engineering[Computer Science] Student From Rajasthan. He has a knowledge of C, C++, Java, Adv. Java, HTML and little bit knowledge of PHP.

Comments (1)

Trackback URL | Comments RSS Feed

  1. Miss Ida says:

    Hello, I am ida, please help me to built one program using C++, the program is to enable process of converting number to binary or octal number format.Program will start by requesting user to key-in any number.Then, the user can choose whether want to convert the number to binary number format or octal number format.This program is should generate the code based on the selection user.The output will be display to user based on the selection before.All the process in converting number to binary or octal format number will be implement using stack with linked list.

Leave a Reply