CS 2733, Fall 2007
Computer Organization II
Homework 1

Binary, Decimal, and Hexadecimal

Read these instructions carefully. For this assignment, you will write a program that converts integers to and from binary, decimal, and hexadecimal. You may write your program in Java, C++, or C. You are required to use the Linux main computers at UTSA to do this assignment. Your program will take three command-line arguments:

  1. A single character telling what to convert from - h for hexadecimal, d for decimal, or b for binary.
  2. Another character telling what to convert to - again, one of h, d, or b.
  3. A string of digits representing the number to convert from
Your program will print to the standard output one of these: Call your program hex, i.e., the Java source file would be called hex.java.

Here are some examples of using the program:

% java hex b d 1010
binary 1010 is decimal 10
% java hex h d 123456
hexadecimal 123456 is decimal 1193046
% java hex d h 12345678
decimal 12345678 is hexadecimal bc614e
% java hex a b 123
Usage: java hex [ h | d | b ] [ h | d | b]
% java hex h d bc614e
hexadecimal bc614e is decimal 12345678
% java hex d h 32
decimal 32 is hexadecimal 20
% java hex d h 1000000000
decimal 1000000000 is hexadecimal 3b9aca00
% java hex d b 1000000000
decimal 1000000000 is binary 111011100110101100101000000000

Your program should not print any extraneous information. This is very important; your program should print only what is asked for, nothing more, since we will be grading it using automated scripts. Your program code should fit in a single file and be well-documented so that a reader not familiar with the computer language can still follow the algorithms and intent of your program through your comments.

To turn in your program, email your one file of source code as an attachment to your professor on or before 11:59pm, August 30, 2007. Note: Email your assignment from your account on the UTSA Computer Science network, i.e., the account created for you for this class and your other computer science classes. Make sure to include your name in your program comments. Do not email the executable binary or class file; send just the source code.

For this assignment, use the main computers located in the Sun lab or remotely by ssh login. Some of the hostnames are:

main201.cs.utsa.edu
main202.cs.utsa.edu
main203.cs.utsa.edu
...
main209.cs.utsa.edu
These computers run Linux. Log in using your username and password. Use pico or vi to edit your program. Use javac, gcc, or g++ to compile your program.

Don't collaborate. Don't copy. Read the comments about academic dishonesty in the syllabus.