
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Decimal to Binary conversion\n
- Stack multiple progress bars with Bootstrap
- Quickly convert Decimal to other bases in C#
- Quickly convert Decimal to other bases in Python
- C Program for Decimal to Binary Conversion?
- Decimal to binary list conversion in Python
- Decimal to Binary conversion using C Programming
- Implicit conversion from Int16 to Decimal in C#
- Implicit conversion from Char to Decimal in C#
- Implicit conversion from UInt64 to Decimal in C#
- Implicit conversion from Int32 to Decimal in C#
- Implicit conversion from Byte to Decimal in C#
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Program for decimal to hexadecimal conversion in C++

Advertisements