C Programming Code Examples C > Conversions Code Examples Program to Convert Octal to Binary Program to Convert Octal to Binary In this program, the octal number to decimal to decimal at first. Then, the decimal number is converted to binary number. #include <stdio.h> #include <math.h> long long convertOctalToBinary(int octalNumber); int main() { int octalNumber; printf("Enter an octal number: "); scanf("%d", &octalNumber); printf("%d in octal = %lld in binary", octalNumber, convertOctalToBinary(octalNumber)); return 0; } long long convertOctalToBinary(int octalNumber) { int decimalNumber = 0, j = 0; long long binaryNumber = 0; while(octalNumber != 0) { decimalNumber += (octalNumber%10) * pow(8,j); ++j; octalNumber/=10; } j = 1; while (decimalNumber != 0) { binaryNumber += (decimalNumber % 2) * j; decimalNumber /= 2; j *= 10; } return binaryNumber; }