PHYSICS 201 - La Salle University



|CSC 157 |Name: ________________________ |

|LAB 2 |September 6, 2001 |

Part 1. Binary and hexadecimal numbers.

All of the information stored in and processed by a computer is represented in bits (binary digits, 1's and 0's). Why?

Convert the following decimal numbers into binary and hexadecimal.

|Decimal |Binary |Hex |

|71 | | |

|43 | | |

|52 | | |

Convert the following binary numbers into decimal.

|Binary |Decimal |Hex |

|10100101 | | |

|01001010 | | |

|10111011 | | |

Part 2. A program that converts to binary form.

Add the following three statements to the main method of a program.

int num;

num=3;

System.out.println(Integer.toBinaryString(num));

Run the program. What is the output?

| |

Use the drop-down lists to find a way to do for hexadecimal what the above program does for binary.

Part 3. Negative Numbers.

Let us extend our representation to include negative numbers. Note that -13 is that number which when added to +13 gives zero. Assuming we are using eight bits to represent a number, calculate the two’s complement of 13. First replaces 1’s with 0’s and vice versa.

|0 |0 |0 |0 |1 |1 |0 |1 |

| | | | | | | | |

Next add 1 to your result.

| | | | | | | | | |

|+ |0 |0 |0 |0 |0 |0 |0 |1 |

| | | | | | | | | |

Now demonstrate that 5 + (-5) = 0

| |0 |0 |0 |0 |1 |1 |0 |1 |

|+ | | | | | | | | |

| |0 |0 |0 |0 |0 |0 |0 |0 |

Repeat the steps above to find –83. (0’s ( 1’s) Enter the binary equivalent of 83 in the first row, take the complement and place it in the second row.

| | | | | | | | |

| | | | | | | | |

And add 1.

| | | | | | | | | |

|+ |0 |0 |0 |0 |0 |0 |0 |1 |

| | | | | | | | | |

Then add 5 and –83.

| | | | | | | | | |

|+ | | | | | | | | |

| | | | | | | | | |

Does the answer make sense? How do you know?

Part 4. Negative Numbers

Set the num variable equal to –3 instead of 3 in the program in Part 2. What is the output?

| |

How many bits are being used to represent the integer?

| |

Part 5. Interpretation

Interpret the following eight-bit binary string

|1 |0 |

|B. As an signed integer | |

|C. Convert it to hex | |

Part 6. Fractions

Express the following fractions in binary form

|Decimal |Binary |

|24.875 | |

|11.625 | |

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download