-->

program to convert binary no. into octal number system

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
#include<stdio.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 
octalNumber=octalNumber+remainder*j;


        j=j*2;


program to convert octal no. into decimal number system.

//program to convert octal no. into decimal number system.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int k=1,m=0,n,rem,decimal=0;
printf("enter octal value/number for 'n'\n");
scanf("%d",&n);
while(n!=0)
   {
      rem=n%10;
      decimal=decimal+rem*pow(8,m);
      n=n/10;
      m++;
   }
printf("decimal is=%d\n",decimal);
getch();
}

logics in mind or applied:-
->if octal number is 234
-> we have to get first 4 and we multiply this with power( you can say increasing or decreasing)of 8
-> we have to add all 
->we display the last value

program to convert decimal into octal

//program to convert decimal number into octal number system.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int k=1,m=0,n,rem,octal=0;
printf("enter decimal value/number of 'n'\n");
scanf("%d",&n);
while(n!=0)
   {
      rem=n%8;
      octal=octal+rem*pow(10,m);
      n=n/2;
      m++;
   }
printf("octal is=%d\n",octal);
getch();
}