Convert Decimal to Hexadecimal using Stack in Java

You all are aware of Stacks. It performs two basic operations push and pop. The push operation adds an element to the top of the list, or initializing the stack if it is empty and the pop operation removes an item from the top of the list. Using these operations, we have converted a decimal number into Hexadecimal .
  1. Divide the decimal number by 16
  2. Treat the division as an integer division. Write down the remainder (in hexadecimal).
  3. Divide the result again by 16.
  4. Treat the division as an integer division. Repeat step 2 and 3 until result is 0.
  5. The hex value is the digit sequence of the remainders from the last to first.

HEXADECIMAL 0 1 2 3 4 5 6 7 8 9 A  B  C  D  E  F 
DECIMAL     0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 


Convert Decimal to Hexadecimal using Stack


When you run the program, the output will be:

Enter Positive Integer :21
Hexadecimal : 15

2 تعليقات

Thank you for vising

إرسال تعليق

Thank you for vising

أحدث أقدم