Convert Octal to Binary in C

Advertisements

Prev Tutorial Next Tutorial

Convert Octal to Binary in C

In this types of program we takes a Octal number as input and converts it into Binary number. To convert octal to binary number first accept binary as a input then convert into equivalent octal number

  • Take a binary number as input.
  • Make Pair of 3 digits binary number.
  • Convert these three binary pair number into equivalent Decimal number.
  • Combind these decimal number.
  • Done

Programming Steps to Convert Octal to Binary

  • Take a octal number as input.
  • Print the binary value of each digit of a octal number. Use switch statement and while loop to do this.

Convert Octal to Binary in C

#include<stdio.h>
#include<conio.h>
#define MAX 1000

void main()
{
    char octal_number[MAX];
    long i = 0;
    clrscr();
    printf("Please Enter any Octal Number: ");
    scanf("%s", octal_number);
    printf("Equivalent Binary Value: ");
    while (octal_number[i])
    {
	switch(octal_number[i])
	{
	case '0':
	    printf("000"); 
		break;
	case '1':
	    printf("001"); 
		break;
	case '2':
	    printf("010"); 
		break;
	case '3':
	    printf("011"); 
		break;
	case '4':
	    printf("100"); 
		break;
	case '5':
	    printf("101"); 
		break;
	case '6':
	    printf("110"); 
		break;
	case '7':
	    printf("111"); 
		break;
	default:
	    printf("\n Invalid Octal Digit %c ", octal_number[i]);
	    return 0;
	} // switch
	i++;
    } // while
    getch();
}

Output 1

Please Enter any Octal Number: 31
Equivalent Binary Value 110001

Output 2

Please Enter any Octal Number: 62
Equivalent Binary Value 011010

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements