Computer Architecture CPIT 210 LAB 1 Manual Prepared By: Mohammed Ghazi Al Obeidallah malabaidallah@kau.edu.sa
LAB 1 Outline: 1. Students should understand basic concepts of Decimal system, Binary system, and hexadecimal system. 2. Students will be asked to solve some problems to increase their understanding of arithmetic operations on binary and hexadecimal numbering systems. 3. Students will understand how to convert from any numbering system to another. LAB 1 main Outcome: 1. Students will be able to convert from any numbering system to another.
A Brief Review of Number Systems: Table 1: Numbering systems Hexadecimal Binary Decimal 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 A 1010 10 B 1011 11 C 1100 12 D 1101 13 E 1110 14 F 1111 15 1. Two s complement notation of Binary numbers: The two s complement of a binary integer is formed by reversing its bits and adding 1. Example: 000111110011 111000001101 2. Two s complement notation of Hexadecimal numbers: To form the two s complement of a hexadecimal integer, reverse all bits and add 1. An easy way to reverse all bits of a hexadecimal digit is to subtract the digit from 15 (F). Here are several examples of hexadecimal integers converted to their two s complements: 6A3D (F-6)(F-A)(F-3)(F-D) 95C2 95C2 + 1 95C3 95C3 (F-9)(F-5)(F-C)(F-3) 6A3C 6A3C + 1 6A3D DE10 (F-D)(F-E)(F-1)(F-0) 21EF 21EF + 1 21F0 3. Converting unsigned decimal to binary To translate an unsigned decimal integer into binary, repeatedly divide the decimal value by 2, saving each remainder as a binary digit. Example: 37 00100101 4. Converting unsigned binary to decimal Example: 00001001 (1 x 2 0 ) + (1 X 2 3 ) =9
5. Converting signed decimal to binary Here are the steps to follow: 1- Convert the absolute value of the decimal integer to binary. 2- If the original integer was negative, form the two s complement of the binary number. Example: -43 11010101 1. The binary representation of the unsigned 43 is 00101011. 2. Because the original value was negative, we form the two s complement of 00101011 which is 11010101. This is the representation of -43 decimal. 6. Converting signed binary to decimal Here are the steps to follow: - If the highest bit is a 1, it is currently stored in a two s complement notation. You must form its two s complement notation a second time to get its positive equivalent. Then you can convert this new number to decimal as if it were an unsigned binary integer. - If the highest bit is a 0, you can convert it to decimal as it were an unsigned binary integer. For example, signed binary 11110000 has a 1 in highest bit, indicating that is a negative integer. Step 1: form the twos complement 00010000 Step 2: convert to decimal 16 step 3: infer the decimal value -16 7. Converting hexadecimal to binary Each digit in a hexadecimal integer represents four binary bits: Example: 0AB3 0000 1010 1011 0011 8. Converting binary to hexadecimal Each four bits in a binary integer represents a single hexadecimal integer. Example: 0000 0101 0011 1010 053A 9. Converting unsigned decimal to hexadecimal To convert an unsigned decimal integer to hexadecimal, repeatedly divide the decimal value by 16, and keep each remainder as a hexadecimal digit. For example: 422 (1A6) hex 10. Converting Signed decimal to hexadecimal To convert a signed decimal integer to hexadecimal, do the following: - Convert the absolute value of the decimal integer to hexadecimal. - If the decimal integer was negative, form the two s complement of the hexadecimal number. Example: -43 D5, here are the steps I did to convert it: Step 1: convert 43 to hexadecimal 2B Step 2: because the decimal integer is negative, we will form the twos complement of a hexadecimal. 2B D4 +1 D5
11. Converting signed hexadecimal to decimal To convert a signed hexadecimal integer to a decimal, do the following: - If the hexadecimal integer is negative, form its two s complement; otherwise, retain as is. - Using the integer from the previous step, convert it to decimal. If the original value was negative, attach a minus sign to the begging of the decimal integer. Important Note: You can tell if a hexadecimal integer is positive or negative by inspecting its most significant (highest) digit. If the digit is >=8, the number is negative; if the digit is <=7, the number is positive. For example, hexadecimal 8A21 is negative, and 7FD9 is positive. For example, signed hexadecimal A02F has an A in highest digit, indicating that is a negative integer. Step 1: form the twos complement of a hexadecimal 5FD0 + 1 _ 5FD1 Step 2: convert to decimal (1 X 16 0 ) + (13 X 16 1 ) + (15 X 16 2 ) + (5 X 16 3 ) = 24529 Step 3: infer the decimal value -24529 Homework 1 : Q 1) Complete table 1, by writing numbers from 0 to 40.