Binary , Decimal , Octal , Hexadecimal Numbers INTERCONVERSION

 BINARY TO DECIMAL NUMBER .


#include <stdio.h>

int main()
{
    int binary,rem = 0,base = 1,deci = 0;
    printf("Enter any binary number: ");
    scanf("%d", &binary);
    int temp =  binary;
    while (temp > 0)
    {
        rem = temp % 10;
        deci += rem * base;
        base *= 2;
        temp /= 10;
    }
    printf("Binary number %d is equal to %d
decimal number.",binary,deci);
    return 0;
}


DECIMAL TO BINARY NUMBER.


#include <stdio.h>

int main()
{
    int deci,rem = 0,base = 1,binary = 0;
    printf("Enter a number: ");
    scanf("%d", &deci);
    int temp =  deci;
    while (temp > 0)
    {
        rem = temp % 2;
        binary += rem * base;
        base *= 10;
        temp /= 2;
    }
    printf("Binary number %d is equal to %d decimal number.",binary,deci);
    return 0;
}



DECIMAL TO OCTAL NUMBER.

#include <stdio.h>

int main()
{
    int deci, rem = 0, base = 1, octal = 0;
    printf("Enter a number: ");
    scanf("%d", &deci);
    int temp = deci;
    while (temp > 0)
    {
        rem = temp % 8;
        octal += rem * base;
        base *= 10;
        temp /= 8;
    }
    printf("Octal number %d is equal to %d decimal number.", octal, deci);
    return 0;
}


OCTAL TO DECIMAL NUMBER.


#include <stdio.h>

int main()
{
    int octal, rem = 0, base = 1, deci = 0;
    printf("Enter a octal number: ");
    scanf("%d", &octal);
    int temp = octal;
    while (temp > 0)
    {
        rem = temp % 10;
        deci += rem * base;
        base *= 8;
        temp /= 10;
    }
    printf("Octal number %d is equal to %d decimal number.", octal, deci);
    return 0;
}


HEXADECIMAL TO DECIMAL NUMBER.


#include <stdio.h>

int main()
{
    int hexa, rem = 0, base = 1, deci = 0;
    printf("Enter a hexadecimal number: ");
    scanf("%d", &hexa);
    int temp = hexa;
    while (temp > 0)
    {
        rem = temp % 10;
        deci = deci + base * rem;
        base = base * 16;
        temp = temp / 10;
    }
    printf("hexadecimal number %d is equal to %d decimal number.",hexa,deci);
}


DECIMAL TO HEXADECIMAL NUMBER.


#include <stdio.h>

int main()
{
    int deci, rem = 0, base = 1, hexa = 0;
    printf("Enter a number: ");
    scanf("%d", &deci);
    int temp = deci;
    while (temp > 0)
    {
        rem = temp % 16;
        hexa += rem * base;
        base *= 10;
        temp /= 16;
    }
    printf("Hexadecimal number %d is equal to %d decimal number.", hexa, deci);
    return 0;
}


BINARY TO HEXADECIMAL.



Popular posts from this blog

AKTU PROGRAMING FOR PROBLEM SOLVING LAB ( ALL QUESTION )

Pattern with nested loop under construction