Convert Binary to Octal in C

Advertisements

Prev Tutorial Next Tutorial

Write a Program in C to Convert Binary to Octal

In this types of program we takes a binary number as input and converts it into Octal number.

  • 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.
  • Add all the multiplied digits.
  • Here Combine the result of all groups to get the output.

Convert Binary to Octal in C

#include<stdio.h>
#include<conio.h>
 
void main()
{
    long int binary_number, octal_number = 0, j = 1, remainder;
 
    printf("Please Enter any Binary Number: ");
    scanf("%ld", &binary_number);
    while (binary_number != 0)
    {
        remainder = binary_number % 10;
        octal_number = octal_number + remainder * j;
        j = j * 2;
        binary_number = binary_number / 10;
    }
    printf("Equivalent Octal Value: %lo", octal_number);
 	getch();
}

Output

Please Enter any Binary Number: 11001
Equivalent Octal Value: 31 

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements