-->

program to convert hexadecimal number into binary number system.

//program to convert hexadecimal number into binary number system.
#include<stdio.h>
#define MAX 100
void main()
{
    char binaryNumber[MAX],hexaDecimal[MAX];
    long int i=0;

    printf("Enter any hexadecimal number: ");
    scanf("%s",hexaDecimal);

    printf("\nEquivalent binary value: ");
    while(hexaDecimal[i])
{
         switch(hexaDecimal[i])
      {
             case '0': printf("0000"); 
                              break;
             case '1': printf("0001"); 
                             break;
             case '2': printf("0010"); 
                             break;
             case '3': printf("0011"); 
                            break;
             case '4': printf("0100"); 
                             break;
             case '5': printf("0101"); 
                            break;
             case '6': printf("0110"); 
                           break;
             case '7': printf("0111"); 
                          break;
             case '8': printf("1000"); 
                           break;
             case '9': printf("1001"); 
                          break;
             case 'A': case 'a': printf("1010"); 
                         break;
             case 'B': case 'b': printf("1011"); 
                         break;
             case 'C': case 'c': printf("1100"); 
                         break;
             case 'D': case 'd': printf("1101"); 
                          break;
             case 'E': case 'e': printf("1110"); 
                         break;
             case 'F': case 'f': printf("1111"); 
                        break;
        
             default:  
                    printf("\nInvalid hexadecimal digit %c ",hexaDecimal[i]);

         }                           
         i++;
    }
    getch();

}
logics in mind/applied:
->we enter here hexadecimal number
->we make group of 4 bits equivalent of each digit
->for this, we check each digit.
->To check digit, we use loop and switch with each digit equivalent.


program to convert binary no. to hexadecimal number system.

//program to convert binary no. to hexadecimal number system.
#include<stdio.h>
#include<conio.h>
void main()
{
   
    long int binary_Number,hexadecimalNumber=0,j=1,remainder;
   
    printf("Enter any number any binary number: ");
    scanf("%ld",&binary_Number);
   
    while(binary_Number!=0)
{
    remainder=binary_Number%10;
    hexadecimalNumber=hexadecimalNumber+remainder*j;
        j=j*2;
        binary_Number=binary_Number/10;
      }

    printf("Equivalent hexadecimal value: %lX",hexadecimalNumber);

    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 

hexdecimalNumber=hexadecimalNumber+remainder*j;

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();
}

program to convert hexadecimal number into decimal .

//program to convert hexadecimal number into decimal .
#include <stdio.h>
#include <math.h>
#include <string.h>
void main()
{
    char hex_number[20];
    long long deci=0, place=1;
    int i = 0, val, len;
    /*
     * entering hexadecimal number from user
     */
    printf("Enter any hexadecimal number: \n");
    gets(hex_number);
     
    /* get/find the length of total number of hex digit (inputted as string)*/
    len = strlen(hex_number);
     len--;//it decreases the value of total length by 1 because we need one less value
       //  for multiplication. and array stores value from location 0
    /*
     * Converts the hexadecimal number to decimal number
     * using algorithm/formula for conversion
           deci = deci + (hex_number[i] * 16 ^ power)
     */
    for(i=0; hex_number[i]!='\0'; i++)
    {
        /*
         * Finds the decimal each equivalent hexadecimal digit
         following logic takes one character,converts into value as val  and then 
          goes for calculation.
         */
        switch(hex_number[i])
        {
            case '0':
                val = 0;
                break;
            case '1':
                val = 1;
                break;
            case '2':
                val = 2;
                break;
            case '3':
                val = 3;
                break;
            case '4':
                val = 4;
                break;
            case '5':
                val = 5;
                break;
            case '6':
                val = 6;
                break;
            case '7':
                val = 7;
                break;
            case '8':
                val = 8;
                break;
            case '9':
                val = 9;
                break;
            case 'a':
            case 'A':
                val = 10;
                break;
            case 'b':
            case 'B':
                val = 11;
                break;
            case 'c':
            case 'C':
                val = 12;
                break;
            case 'd':
            case 'D':
                val = 13;
                break;
            case 'e':
            case 'E':
                val = 14;
                break;
            case 'f':
            case 'F':
                val = 15;
                break;
        }
        deci += val * pow(16, len);
        len--;
    }
    printf("\Hexadecimal number = %s\n", hex_number);
    printf("equivalent Decimal number = %ld", deci);  
}


logics in mind:

-> hexadecimal number contains characters A,B,C,D,E, and F
-> we have to check and extract all characters one by one then we go for multiplication with increasing or
     decreasing power
->we have to go for sum
->display that sum