Write a C program to read Octal number from user and convert to Binary number system. How to convert from Octal number system to Binary number system in C.

Input Octal number: (172)

Output Binary number: (01111010)

Happy coding ;)

**Example:**Input Octal number: (172)

_{8}Output Binary number: (01111010)

_{2}### Required knowledge:

Basic C programming, For loop#### Octal number system:

Octal number system is a base 8 number system. It uses 8 symbols to represent all its numbers i.e. 0 1 2 3 4 5 6 7#### Binary number system:

Binary number system is a base 2 number system. It uses only two symbols i.e. 0 and 1 to represent all numbers.### Algorithm to convert Octal to Binary:

Algorithm to convert from Octal to Binary is simple. Separate each octal digit and write the binary equivalent of each octal digit.**Octal to Binary conversion table:**Decimal | Octal | Binary |

0 | 0 | 000 |

1 | 1 | 001 |

2 | 2 | 010 |

3 | 3 | 011 |

4 | 4 | 100 |

5 | 5 | 101 |

6 | 6 | 110 |

7 | 7 | 111 |

Algorithm Conversion from Octal to Binarybegin:read(OCTAL);OCTALVALUES[] ← 0, 1, 10, 11, 100, 101, 110, 111;BINARY← 0;REM← 0;PLACE← 1;While(OCTAL!=0)begin:REM←OCTAL% 10;BINARY← (OCTALVALUES[REM] *PLACE) +BINARY;OCTAL←OCTAL/ 10;PLACE←PLACE* 1000;end;write('Binary ='BINARY);end;

### Program:

/** * C program to convert Octal number system to Binary number system */ #include <stdio.h> int main() { int OCTALVALUES[] = {0, 1, 10, 11, 100, 101, 110, 111}; long long octal, tempOctal, binary, place; int rem; /* * Reads Octal number from user */ printf("Enter any Octal number: "); scanf("%lld", &octal); tempOctal = octal; binary = 0; place = 1; /* * Finds Binary of the octal number */ while(tempOctal!=0) { rem = tempOctal % 10; binary = (OCTALVALUES[rem] * place) + binary; tempOctal /= 10; place *= 1000; } printf("\nOctal number = %lld\n", octal); printf("Binary number = %lld", binary); return 0; }

Output

Enter any Octal number: 1720

Octal number = 1720

Binary number = 1111010000

Octal number = 1720

Binary number = 1111010000

Happy coding ;)

### You may also like

- Loop programming exercises and solutions in C.
- C program to find one's complement of a binary number.
- C program to find two's complement of a binary number.
- C program to convert Binary to Octal number system.
- C program to convert Binary to Decimal number system.
- C program to convert Binary to Hexadecimal number system.
- C program to convert Octal to Decimal number system.
- C program to convert Octal to Hexadecimal number system.
- C program to convert Decimal to Binary number system.
- C program to convert Decimal to Octal number system.
- C program to convert Decimal to Hexadecimal number system.
- C program to convert Hexadecimal to Binary number system.
- C program to convert Hexadecimal to Octal number system.
- C program to convert Hexadecimal to Decimal number system.

If you're actually searching for none risk plan to make money online I can show you the software which is extremely safer and how anyone can start profiting with Trend Trader. Check by visiting their Trend Trader Official Website

ReplyDeleteFirst time, I used Binary matrix pro and got loss, loss and loss. I entry 73 trades by using “binary matrix pro” and the result “ 66 is trade loss on the other hand, only 5 trades profitable . One of my friend recommend me to use “Trend Trader” Than I invest using “Trend Trader”. Totally 150 trades have profited and my success rate is 95%. I told this matter of my 3 friends when I got my success. They are also profiting. That’s why, I can tell that Trend Trader is the best Binary Signal Software.

ReplyDeleteif you interested you can visit this link to know more details about Trend Trader SystemTrend Trader Official Website