Homework Assignment 1

Number Systems

**Program Due:** Thursday Sep. 14, 2006 at 11:59pm

The best known number system in this world is the decimal number system. We all know what the number 185 represents

In this representation 10 is called base or radix. The number system used in microprocessors is the binary number system. The main difference between this number system and the decimal number system is that instead of 10 digits, the binary number system only contains 2 digits called '0' or '1':2 1 0 185 = 1 * 10 + 8 * 10 + 5 * 10

Here are a few others numeric systems:2 1 0 101 = 1 * 2 + 0 * 2 + 1 * 2

- Octal - base is 8
- Duodecimal - base is 12 (used for some purposes by the Romans)
- Hexadecimal - base is 16
- Vigesimal - base is 20 (used by the Mayans)
- Sexagesimal - base is 60 (used by the Babylonians)

The lab will require you to use the control flow statements, perform simple logical operations, and comminicate with the user via the dialog box.

- To review of basic Java concepts
- To gain experience of working with the JOptionPane and ArrayList classes

Write a method that converts any positive decimal integer to any other number system between 2 and 36. This convertion is not complicated, but it requires a lot of divisions. Here is an example of converting 176 to base 7:

176 / 7 = 25 remainder 1 25 / 7 = 3 remainder 4 3 / 7 = 0 remainder 3

176 = 341 10 7

12345 = 343340 10 5

Now let us convert decimal 10 to base 16. What would be a result? 10. Unfortunately we cannot write 10 since it contains two digits 1 and 0. We have to use other characters for representation. We shall use the alphabet. For bases larger than 10, we will take additional digits from the letters a-z:

10 = a 11 = b ... 15 = f 10 16 10 16 10 10

23332 = a80a 10 13

```
JOptionPane
```

class to read input from the user's keyboard and write messages (output) to
the user's screen. Also you will use the `ArrayList`

class that provides methods to manipulate the size of the array that is used
internally to store the list.

12 = 15 12*3 = 36 = 51 10 7 10 7

You shall use the ```
JOptionPane
```

class to prompt a user for a base and then write output to
the user's screen.

For bases larger than 10, additional digits are chosen from the letters "a-z".

Review the implementation of calculation of Pi at Pi.java. This should help you to deal with

Comment your source code.

Download the BaseForm.java.

ftp your solution to /afs/andrew/course/15/200/www/DE/handin

Your assignment will be graded first by compiling and testing it. After that, we will read your code to determine whether appropriate classes were used, as well as judge the overall style and modularity of your code. Points will be deducted for poor design decisions and un-commented, or un-readable code as determined by your TA.

Here is the point breakdown:

- Part I - 40 points
- Part II - 40 points
- Coding style - 20 points.