Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 2 Summary Overview • Numbers – Decimal, Binary, Octal, Hexadecimal – Their relationship • • • • Sign-magnitude One’s complement Two’s complement Arithmetic operation Positive Numbers • A computer represents positive integers in binary • Three methods for representing negative numbers (signed numbers) are – Sign-magnitude – One’s complement – Two’s complement Sign Magnitude • Representation the number’s sign and magnitude (value) • Positive numbers 0 and negative numbers 1 • e.g. 01000000 = 64 and 11000000 = -64 • Easy for human to understand but it requires some special logic for arithmetic operations (addition, subtraction) Arithmetic Operation • Computers mostly storing information , particularly integers, in byte form • In this section we look how addition and subtraction are performed in computers • To perform mathematical functions, a CPU contains a component called ALU (arithmetic logic unit) – to perform arithmetic operations (addition & subtraction) and logic operation (in next chapter) One’s Complement • The negative number is represented by flipping the number’s bits • E.g., 01001001 becomes 10110110 • E.g. consider 103 + -97 01100111 + (-01100001) = 01100111 + 10011110 = 100000101 (9 bits) 00000101 + 1 = 00000110 (8 bits) 103 – 97 = 6 = 00000110 Try 113 + -42 = ?? and –75 + 13 = ?? Two’s Complement • Makes addition and subtraction simple • The fact that all numbers are stored in 2’s complement form allows the ALU to use just one circuit for all basic mathematical operations • Visual Basic uses 2’s complement representations of numbers Two’s Complement • Rules – – – – Just add all the bits Throw away EAC (“end around carry”) if a – b becomes a + (-b) e.g. 111111 (-1) 10110 (-10) + 001000 (8) + 11101 (-3) 1000111 (7) 110011 (-13) • try again –75 + 13 in 2’s complement Assignment 1 • Question 1.9 (i) -117 – 145 - 117 = 10001011 (2’s) - 145 = 01101111 (2’s) Answer : 11111010 Verify: 00000110 ≠ - 262 (ii) –90 – 133 -90 = 10100110 (2’s) -133 = 01111011 (2’s) Answer: 100100001 Verify: 11011111 = -223