Convert a Decimal Number to Binary Number using Stacks in Java

How to convert decimal into binary using stacks. 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 binary.

For converting decimal number to binary, initially we push all the binary digits formed into the stack. After the entire number has been converted into the binary form, we pop one digit at a time from the stack and print it. Therefore we get the decimal number converted into its proper binary form.

Convert a Decimal Number to Binary Number

Array Implementation of Stack


When you run the program, the output will be:

Enter Decimal Number : 25
25 is converted to Binary is 1 1 0 0 1 

Previous Post Next Post