Java Program to Convert a Decimal Number to Binary Number using Arrays as Stacks
Given an Integer number convert into Binary Number using arrays as a stack.
Input : 10 Output: 1010 Input : 16 Output: 10000
- Divide the number by 2 and store the remainder of the number in the array.
- Divide the number by 2.
- Repeat the process until the number becomes zero.
- Print the array in reverse order.
Binary equivalent: 101110
Time complexity: O(logn) for given input number n
My Personal Notes arrow_drop_up
Please Login to comment...