C Program to Convert Binary to Hexadecimal

Let’s understand how to convert Binary to Hexadecimal in C Programming Language.

C Program to Convert Binary to Hexadecimal

#include <stdio.h>

/*Learn C Programming at CodeAtGlance.com*/

int main()
{
    long intb_value, hex_value = 0, i = 1, remainder;
    printf("Enter the binary number: ");
    scanf("%ld", &binaryval);
    while (binaryval != 0)
    {
       remainder =b_value % 10;
        hex_value = hex_value + remainder * i;
        i = i * 2;
        b_value =b_value / 10;
    }
    printf("Equivalent hexadecimal value: %lX", hex_value);
    return 0;
}

 

Leave a Reply