codescracker


c++

C++ Program to Convert Octal to Binary



« Previous Program Next Program »


Octal to Binary Conversion in C++

To convert octal number to binary number in C++ programming, you have to ask to the user to enter the octal number to convert it into binary number to display the equivalent value in binary format as shown here in the following program.

C++ Programming Code to Convert Octal to Binary

Following C++ program ask to the user to enter any number in octal to convert it into binary, then display the result on the screen:

/* C++ Program - Octal to Binary Conversion */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	long int i=0;
	char octnum[1000];
	cout<<"Enter any Octal Number : ";
	cin>>octnum;
	cout<<"Equivalent Binary Value = ";
	while(octnum[i])
	{
		switch(octnum[i])
		{
			case '0' : cout<<"000";
				break;
			case '1' : cout<<"001";
				break;
			case '2' : cout<<"010";
				break;
			case '3' : cout<<"011";
				break;
			case '4' : cout<<"100";
				break;
			case '5' : cout<<"101";
				break;
			case '6' : cout<<"110";
				break;
			case '7' : cout<<"111";
				break;
			default : cout<<"\nInvalid Octal Digit "<<octnum[i];
				break;
		}
		i++;
	}
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program convert octal to binary

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test