CSCI 1320 - Assignment #2



This assignment has two parts. The first part will have you doing some simple numeric conversions between bases and operations on binary numbers to show that you understand what is going on with them. After that, you will write a short program just to make sure that you have the ability to write, compile, and execute a C program.

Part 1:

A. Convert the following values to hexadecimal. You can feel free to go to binary first then to hex on some.
1. 11010010100010101111 (binary)
2. 2789 (decimal)

B. Now assume that you are dealing with an 16 bit signed number and write the following values in hex.
1. 25 (decimal)
2. -78 (decimal)

C. Run through how you would find this product the "fast" way using binary numbers. (Assume you have a large number of bits here so you don't lose the higher ones.)
11010101*00101001

Part 2: Write a C program that does some of the things from part 1 and prints out the results. For A you only need to do 2. For B do both. For C, use hex notation to put the values into variables and print the product in hex as well.

After you have done this, I want you to write code printing the character values of 45, 56, 98, and 150 followed by the integer values of the characters ' ' (space), 'a', 'A', 'z', and '0'.

Submission: Because this assignment has two parts, you will need to submit them separately. I would like you to give me part 1 in print, either electronic or hand written, just make sure that I can figure out what you are doing either way. Also note that I need to have this part in my hands before I leave on Friday which could be as early as 3pm or so. For the second part of the assignment I want you to e-mail me the source code that you produce at mlewis@cs.trinity.edu. The second page of the handout titled "Linux and vi Helper Sheet" has directions for how you can mail me your program in Linux. Make sure that you have some comments in your code. It is preferable that that top of your code have at least comments identifying you and what the file is.

Answers to Part 1:

Part 1:

A. Convert the following values to hexadecimal. You can feel free to go to binary first then to hex on some.
1

1101
0010
1000
1010
1111
D
2
8
A
F

2. 2789=2048+741=2048+512+229=2048+512+128+101=2048+512+128+64+37=2048+512+128+64+32+4+1

1010
1110
0101
A
E
5

B. Now assume that you are dealing with an 16 bit signed number and write the following values in hex.
1. 25 (decimal)=0000 0000 0001 1001=0019
2. -78 (decimal)=1111 1111 1011 0010=FFB2

0000
0000
0100
1110
+1111
1111
1011
0010
0000
0000
0000
0000

C. Run through how you would find this product the "fast" way using binary numbers. (Assume you have a large number of bits here so you don't lose the higher ones.)
11010101*00101001

11010101
+00101001
11010101
11010101000
1101010100000
10001000011101