# Binary To Octal Conversion

## Binary to Octal Conversion:-

Binary to octal conversion can be easily done with the help of simple calculations. The following section includes a stepwise procedure for such a conversion. In this process, a binary number is inputted by a user and is later converted to an octal number.

Read Also: Program for Number can be expressed as a sum of two prime numbers ### Working:-

Step 1. Start

Step 2. Input a binary number

Step 3. Divide the number into groups of three bits.

Step 4. Multiply each bit from this group with the power of 2 and add them consecutively.

Step 5. Combine the results from all groups to generate the output.

Step 6. Print the octal number.

Step 7. Stop

### C Programfor Binary to Octal Conversion

```/** C Program to Convert Binary to Octal*/

#include<stdio.h>

int main()

{
//For initialize variables
long int binary_num, octal_num = 0, j = 1, rem;

//Inserting the binary number from the user

printf("Enter a binary number: ");
scanf("%ld", &binary_num);

// while loop for number conversion

while(binary_num != 0)
{

rem = binary_num % 10;
octal_num = octal_num + rem * j;       //j*=2
j = j * 2;       //binary_num/10;
binary_num = binary_num / 10;

}

printf("Equivalent octal value: %ld", octal_num);

return 0;
}

```

### Output

```Enter any binary number 10101

Equivalent octal value: 25```

•  0 0