C Programming Code Examples C > Conversions Code Examples C Program to Convert Binary to Octal C Program to Convert Binary to Octal This program takes a binary number as input and converts to octal. Take a binary number as input. Divide the binary number into groups of 3 bits. For each group of 3 bits, multiply each bit with the power of 2 and add them consecutively. Combine the result of all groups to get the output. #include <stdio.h> int main() { long int binarynumber, octalnumber = 0, j = 1, remainder; printf("Enter the value for binary number: "); scanf("%ld", &binarynumber); while (binarynumber != 0) { remainder = binarynumber % 10; octalnumber = octalnumber + remainder * j; j = j * 2; binarynumber = binarynumber / 10; } printf("Equivalent octal value: %lo", octalnumber); return 0; } Take a binary number as input and store it in the variable binarynumber. Obtain the remainder and quotient of the input number by dividing it by 10. Multiply the obtained remainder with variable j and increment the variable octalnumber with this value. Increment the variable j by 2 and override the variable binarynumber with the quotient obtained. Repeat the steps 2-4 until the variable binarynumber becomes zero. Print the variable octalnumber as output.