Convert Octal to Binary in C
Advertisements
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
Google Advertisment