> For the complete documentation index, see [llms.txt](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/tutorial/tutorial-1-c-and-cubeide-setup/homework/task-3-number-system-conversion.md).

# Task 3 : Number system conversion

<details>

<summary>Authors</summary>

Li Chi Kin (<ckliam@connect.ust.hk>)

</details>

## Problem

This task is designed for fun :) &#x20;

There are so many number systems. We encounter some unusual number systems in our daily lives, namely, decimal (base 10), duodecimal (base 12), and trinary (base 3).&#x20;

Write a Number System Converter that converts a number from one system to another. You have to handle 3 systems: decimal, duodecimal, and trinary. The converter should be able to convert from/to any of the three systems.

## Assumption

1. There are no spaces between the digits of the input string.
2. The input string is a non-negative integer. Or else it throws an error message.
3. The input and output values are in range:   $$0\leq n\leq 2^{64}-1$$
4. The inputted number system must be an integer.

## Example

This is an example that converts 123123123 from decimal to trinary:

```
Please enter a set of number:
123123123
Please enter the current number system:
10
Please enter the number system you want the set of number be converted to:
3
Output=22120200022011200
```

This is an example that converts 5201314 from decimal to duodecimal (base 12)

```
Please enter a set of number:
5201314
Please enter the current number system:
10
Please enter the number system you want the set of number be converted to:
12
Output=18AA02A
```

You can verify the answer as below:

(A = 10, B = 11)

$$5201314 = 1\times12^{6}+8\times12^{5}+10\times12^4+10\times12^3+0\times12^2+2\times12+10$$

## Example - Error

However, if the user entered a wrong number system, an error message should be printed:

Please enter a set of number:

```
Please enter a set of number:
9999 
Please enter the current number system:
3
Error! That set of number is not a trinary number.
```

```
Please enter a set of number:
ABCDEF 
Please enter the current number system:
12 
Error! That set of number is not a duodecimal number.
```

```
Please enter a set of number:
987456321
Please enter the current number system:
27
Error! The number system is not supported.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hkust-robotics-team.gitbook.io/hkust-robotics-team-software-tutorial/tutorial/tutorial-1-c-and-cubeide-setup/homework/task-3-number-system-conversion.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
