Area 07 · Number system
Any-base converter
Convert numbers between bases 2, 8, 10 and 16 in either direction, checking every digit, without built-in conversions.
- Spec no.
- HO-14
- Level
- Exam-level
- Time box
- 1 h 15 min
- Reference
- Java · C#
- Grading
- Self-assessed · rubric is ours, not DICT's
01 Coverage
| Area | Sub-skills practised | Role |
|---|---|---|
| 01 Data manipulation | String, Validation | Also |
| 07 Number system | Binary, Octal, Decimal, Hexadecimal | Primary |
Sign up to start coding practice
Read the task freely. An account is required before editing and running a solution. Code runs also need an internet connection.
Sign up or sign in02 Requirements
- Each line is from-base number to-base, until q.
- Supported bases are 2, 8, 10 and 16. Anything else prints Unsupported base.
- Accept upper- and lower-case hex digits. A digit that is not legal in the source base prints Invalid digit 'd' for base b.
- Convert source → decimal by positional value (value = value × base + digit), then decimal → target by repeated division. Guard against overflow (print Too large).
- Print the result in upper case. Zero prints 0.
03 Input and output
- Lines of from number to
- q to quit
- The converted number, or an error message
16 b7 2
8 175 10
2 102 10
10 0 16
10 255 8
3 12 10
16 FFFF 10
q10110111
125
Invalid digit '2' for base 2
0
377
Unsupported base
65535Match the sample exactly first, then write at least two test inputs of your own.
04 Edge cases to test
- 9 in base 8
- G in base 16
- Base 3
- A wrong number of fields
05 Starter outline and hints
validate field count and basestoDecimal(text, base) → value or errorfromDecimal(value, to)
Hint 1
DIGITS.indexOf(ch) gives the digit value and tells you when it is too big for the base.
06 Practice rubric
| Criterion | Sub-skills | Look for | Pts |
|---|---|---|---|
| Positional value | DecimalBinaryOctalHexadecimal | Correct decimal value for every supported base. | 30 |
| Repeated division | HexadecimalBinary | Correct digits for every target base, upper case, zero handled. | 25 |
| Digit validation | Validation | Exact error message naming the bad digit. | 25 |
| Parsing | String | Field count and base checks before converting. | 20 |
| Total | 100 | ||
Our own weighting for practice. It is not the DICT scoring scheme.
07 Self-check
Tick only what you have verified by running your own program.
Loading saved checks…
08 Reference solution
Both versions compiled and reproduced the sample output on Java 21 and .NET 8 when this site was built. Reference solutions are in Java and C#. The 2023 FAQ copy also lists C, C++ and Visual Basic 6.0 / .NET; the same structure carries over, but you will need your language's own file and database APIs.
Try the whole brief first. The reference is one correct approach, not the only one, and reading it early removes most of the practice value.
09 Exam-day habits
- Work without internet search to simulate exam conditions.
- Type the sample input yourself and compare your output line by line before you look at the reference.