In this program, we are going to convert the decimal value into hexadecimal values using the programming language C++. These numbers are used in designing digital circuits.

This program can be used in Digital circuit applications. Computers work with binary numbers which use only digits like 0 and 1.Decimal, Hexadecimal, and octave numbers are the human-friendly representation of Binary coded values. Hence, the usage of hexadecimal and other numbers is crucial in analyzing and designing digital circuits. The conversion process is as follows.

1)Initially, find the reminder for the whole Decimal number divided by 16 and find the remainder for each successive quotient divided by 16 and store it in n3,n2,n1and n0 variables until the quotient becomes zero.

It may be a little confusing at first but we can understand it on seeing the calculation as shown below

x = a / 16; /*Finding reminder and successive reminders of the decimal number(a)*/ n0 = a % 16; y = x / 16; n1 = x % 16; z = y / 16; n2 = y % 16; s = z / 16; n3 = z % 16;

2)Store these variables in an array b[4] to give 4 digit flexibility.

3)Change the numbers into hex characters if the initially converted value is greater than 9. For e.g, 'A' for 10,'B' for 11 up to 'F' for 15. Finally, the hexadecimal number is printed.

The test runs are shown below,

Submitted by Mohamed Adila.A (Adila)

Download packets of source code on Coders Packet

## Comments