Day 2: Number Systems
Exercise
Write a Java program to convert decimal to various other number systems.
Introduction
A number system is a method of representing numerical values using a set of symbols. Everybody is familiar with decimal which uses the symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. A number system can be based on any collection of symbols with at least two symbols. The following are some common number systems and the symbols they use:
| Number System | Symbols used |
|---|---|
| Binary | 0, and 1 |
| Octal | 0, 1, 2, 3, 4, 5, 6, and 7 |
| Hexadecimal | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, and f |
Algorithm
- Read a tutorial on number systems if you are not familiar with the process for converting between number systems.
- Implement the core functionality using a text-based interface for I/O.
- Build a GUI to wrap your implementation.
Resources
- Main.java (text-based interface)
- Numeral system (Wikipedia)
Hints
- Remember the modulo (%) operator will calculate the remainder of a division.
- Try augmenting your program by implementing conversion from arbitrary number systems instead of just decimal.