Assignment 1

 

CISC221, Fall 2001

Queen's University

Due: October 10, 2001 12:00

Where: In drop-off box marked cisc221 outside Goodwin 235

No late assignments!

See below notes for instructions.

 

Assignment 1: Base Conversion

Develop a program in java that converts the input of a decimal character string into the following output:

  1. Hexadecimal with exactly four digits. (Small numbers must be padded on the left with zeros).
  2. Two's Complement Binary. This output format interprets decimal input as a 16-bit twos-complement signed integer (negative numbers must padded with ones).
  3. Two 8-bit ASCII characters. Bytes which are unprintable characters (the ASCII codes 0 through 31 and 127 through 255) are replaced by spaces.

The input is to be interpreted as the value of a PEP/6 integer, which is exactly 16 bits wide. So if a decimal is too large to fit into sixteen bits, it should be flagged as an error. Your program should implement it's own base conversions using one of the methods suggested in class, not using ANY conversions native to java! You may however use native java print commands to convert values to characters.Be careful to check for unprintable characters first!

If the input cannot be interpreted as a number, the program should print an error message.

Design

You don't have to expend any effort on the user interface. Just have the program read constants line-by-line from its standard input, and print to the standard output.

Tip

Your program should convert the characters in the input string to decimal by checking position of the character.
Then use this value as input for methods that implement the base conversion printouts.

Documentation

Be sure to test your program with a number of representative test cases and explain your motivation for those test cases. Include the test results and motivations as a single hardcopy documentation page that you hand in with your code.

What to Submit

Your (hard-copy) submission should include: The printout of one *.java file and one documentation file. Remember to include comments in your program code. Make sure your name and student number are on every page. Please number and staple pages together in a way that allows us to read them. For a complete overview of instructions regarding submission, see Assignments