C Program to Convert Binary to Hexadecimal Number

In this tutorial, we will explain a simple program to convert the binary number into the hexadecimal number. We have not used any number validation in this program as it is designed for the beginners for learning purpose.

You can modify this program to validate the number entered by the user during the program execution, then the user can only enter the binary number to hexadecimal number conversion using c programming language.

Copy below c program and execute it with c compiler to see the output of the program and also start converting the number system from binary to hexadecimal number.

Enter the binary number: 10000
Equivalent hexadecimal value: 10

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers.

1 thought on “C Program to Convert Binary to Hexadecimal Number”

    int main() {
        long int binaryval, decimalval = 0;
        printf("Enter the binary number: ");
        scanf("%ld", &binaryval);
        do {
            decimalval = (decimalval << 1) + binaryval % 10;
        } while (binaryval /= 10);
        printf("Equivalent hexadecimal value: %lX", decimalval);
        return 0;

    You're calculating the decimal value and showing it as hex, so call it that.... and simplify the logic down by leveraging loose boolean and ditching the variables for nothing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.