we have two methods for this conversion.
either we can convert binary to decimal and then decimal to octal
or we can directly convert into octal using 3 bits system.
//program to convert binary no. into octal number system
either we can convert binary to decimal and then decimal to octal
or we can directly convert into octal using 3 bits system.
//program to convert binary no. into octal number system
#include<stdio.h>
#include<conio.h>
#include<conio.h>
void main()
{
long int binary_Number,octalNumber=0,j=1,remainder;
printf("Enter any number any
binary number: ");
scanf("%ld",&binary_Number);
while(binary_Number!=0)
{
{
remainder=binary_Number%10;
octalNumber=octalNumber+remainder*j;
j=j*2;
binary_Number=binary_Number/10;
}
printf("Equivalent octal value:
%lo",octalNumber);
getch();
}
logics in mind:-
->we have to input a binary number, say 111
->we make group of 3 bits from right side, and for this, we use
logics in mind:-
->we have to input a binary number, say 111
->we make group of 3 bits from right side, and for this, we use
octalNumber=octalNumber+remainder*j;
j=j*2;