
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decimal to Multiple Bases Conversion with Stack
For multiple-base conversions, set a variable and add the base you want to calculate.
Here, for our example, I have set the variable baseNum as 2 −
int baseNum = 2;
In the same way, if you want base 8, then set the above as −
int baseNum = 2;
You can also get the above variable value as user input.
After getting the value, set a stack and get the values −
Stack s = new Stack(); do { s.Push(n % baseNum); n /= baseNum; } while (n != 0);
After using the stack, pop out the elements. That would give you the result.
Let’s say the number n is 45, then the result in binary would be −
Result... 101101
Advertisements