CS 135-30 Lab Assignment 1

Wednesday, September 9, 2009


Required Assignment:

 In this lab exercise you will write a Java class to operate on Hexadecimal numbers.

The input to your program are two unsigned (non-negative) integers represented as Hexadecimal numbers, and separated by a blank space. Your program must print out the two numbers in decimal notation and then print out the sum of the two numbers (in decimal notation).

For example, if the input is x000A and x0018 then the program prints out 10 24 34.
Assume 16 bit representation (i.e., 4 Hex digits).


Extra Points:

Now assume that your program must handle positive and negative integers and assume 2's complement representation (but expressed in Hex). Repeat the above assignment for the general case -- i.e., set of all integers and using 2's complement representation.


Practice Problem/Optional Work:

In this extra "assignment" you will write a Java class to convert ASCII characters to text (and vice versa).

The input to your program is a string of text representing ASCI characters in hex format (assume the input string will be on one line only). The ASCII characters (in hex) correspond to two integers followed by an arithmetic operator, i.e., a b op. Your program must read this input string and convert it to the corresponding integers and the arithmetic operator, i.e., a op b. You must then provide the answer to the arithmetic equation but provide the answer as an ASCI string. For example, if the input string to your program is (in hex format):


31322035202A


then the string corresponds to '12 5 *' (note that each ASCII character is 2 bytes or 2 hex digits, and the two integers and the arithmetic operator are separated by a space). The output is the ASCI string corresponding to 60 (i.e., 12*5) i.e., the string:


3630


Note that the ASCII characters are 2 bytes long and expressed in Hex format. You can use the Java code provided to you to look up the ASCII character tables. For this assignment, process the string:

313020333034202B


You can use the Java code provided to you to look up the ASCII character tables. You must submit your Java code, and your answer.