Convert Binary to Hexadecimal in C

Advertisements

Prev Tutorial Next Tutorial

Convert Binary to Hexadecimal Program in C

In this types of program we takes a binary number as input and converts it into Hexadecimal number.

Binary NumberBinary number system is a base 2 number system. Binary number system uses only two symbols to represent all its values i.e. 0 and 1

HexaDecimal NumberHexadecimal number system is base 16 number system. Hexadecimal number system uses 16 symbols to represent all its values i.e. 1B

Binary to Hexadecimal Covertion Method

  • Take a binary number as input.
  • Group all binary bits to 4 digits starting from right side.
  • Write corresponding hexadecimal value of each grouped digit.
convert binary to hexadecimal in c

Decimal, Binary, Hexadecimal Table

DecimalBinaryHexadecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

Convert Binary to Hexadecimal in C

#include<stdio.h>
#include<conio.h>

void main()
{
    long int binary_number, hexadecimal_number = 0, i = 1, remainder;
    clrscr();
    printf("Please Enter any Binary Number: ");
    scanf("%ld", &binary_number);
    while (binary_number != 0)
    {
        remainder = binary_number % 10;
        hexadecimal_number = hexadecimal_number + remainder * i;
        i = i * 2;
        binary_number = binary_number / 10;
    }
    printf("Equivalent Hexadecimal Number %lX", hexadecimal_number);
   
getch();
}

Output 1

Please Enter any Binary Number: 10011
Equivalent Hexadecimal Number: 13

Output 2

Please Enter any Binary Number: 11011
Equivalent Hexadecimal Number: 1B

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements