C Programming Code Examples C > Conversions Code Examples C Program to Convert Binary to Hexadecimal C Program to Convert Binary to Hexadecimal This program takes a binary number as input and converts to hexadecimal. - Take a binary number as input. - Divide the binary number into groups of 4 bits. For each group of 4 bits, multiply each bit with the power of 2 and add them consecutively. - Combine the result of all groups to get the output. /* C Program to Convert Binary to Hexadecimal */ #include <stdio.h> int main() { long int binaryvalue, hexadecimalvalue = 0, j = 1, remainder; printf("Enter the binary number: "); scanf("%ld", &binaryvalue); while (binaryvalue != 0) { remainder = binaryvalue % 10; hexadecimalvalue = hexadecimalvalue + remainder * j; j = j * 2; binaryvalue = binaryvalue / 10; } printf("Equivalent hexadecimal value: %lX", hexadecimalvalue); return 0; } Take a binary number as input and store it in the variable binaryvalue. Obtain the remainder and quotient of the input number by dividing it by 10. Multiply the obtained remainder with variable j and increment the variable hexadecimalvalue with this value. Increment the variable j by 2 and override the variable binaryvalue with the quotient obtained. Repeat the steps 2-4 until the variable binaryvalue becomes zero. Print the variable hexadecimalvalue as output.