Lecture 7_ Computer Arithmetic _ UBeL.pdf
Document Details
Uploaded by UnderstandableSphinx
Full Transcript
.content { display: none; }.content.active { display: block; } Lecture 7: Computer Arithmetic 2. Notes on Computer Arithmetic Lecture Notes: Computer Arithmetic Objectives/Outcomes: By the end of this lecture, students will be able...
.content { display: none; }.content.active { display: block; } Lecture 7: Computer Arithmetic 2. Notes on Computer Arithmetic Lecture Notes: Computer Arithmetic Objectives/Outcomes: By the end of this lecture, students will be able to: 1. Understand binary operations and positional number systems. 2. Describe and apply different methods for signed integer representation. 3. Explain floating-point representation and perform basic arithmetic operations with floating-point numbers. 4. Convert numbers between different bases. 5. Understand character encoding using various character codes. 6. Perform arithmetic using signed magnitude, one’s complement, and two’s complement representations. 7. Understand and apply error detection and correction techniques in computer systems. 1. Binary Operations and Positional Number Systems Binary Operations: Definition: Operations performed on binary numbers, such as addition, subtraction, multiplication, and division. Basic Operations: Binary Addition: Similar to decimal addition, with carrying over when the sum exceeds 1. Example: 10112 +11012 = 110002 10112+11012=110002 Binary Subtraction: Uses the borrow method, similar to decimal subtraction. Example: 10112 −10012 = 00102 10112−10012=00102 Positional Number Systems: Definition: A system in which the value of a digit is determined by its position in the number and the base of the number system. Common Bases: Binary (Base-2): Uses digits 0 and 1. Octal (Base-8): Uses digits 0 to 7. Decimal (Base-10): Uses digits 0 to 9. Hexadecimal (Base-16): Uses digits 0 to 9 and A to F. Example Question: Q: Convert the binary number 101101 to its decimal equivalent. 2. Signed Integer Representation Signed Magnitude Representation: Definition: The most significant bit (MSB) represents the sign (0 for positive, 1 for negative), while the remaining bits represent the magnitude of the number. Example: In an 8-bit system, +5 is represented as 00000101 and -5 as 10000101. One’s Complement Representation: Definition: Negative numbers are represented by inverting all the bits of the positive number. Example: For +5 as 00000101, the one’s complement of -5 is 11111010. Two’s Complement Representation: Definition: Negative numbers are represented by inverting all the bits of the positive number and adding 1 to the least significant bit (LSB). Example: For +5 as 00000101, the two’s complement of -5 is 11111011. Example Question: Q: Represent -12 in an 8-bit system using signed magnitude, one’s complement, and two’s complement representations. 3. Floating Point Representation Definition: A way to represent real numbers (numbers with fractional parts) in a format that can accommodate a wide range of values by using a normalized form. Components: Sign bit: Indicates whether the number is positive (0) or negative (1). Exponent: Represents the power of the base. Mantissa (or Fraction): Represents the significant digits of the number. IEEE 754 Standard: Single Precision (32-bit): 1 bit for sign, 8 bits for exponent, 23 bits for mantissa. Double Precision (64-bit): 1 bit for sign, 11 bits for exponent, 52 bits for mantissa. Example Question: Q: Explain how the number 5.75 is represented in IEEE 754 single precision floating-point format. 4. Converting Between Bases Binary to Decimal: Multiply each bit by 2 raised to the power of its position and sum the results. Example: Convert 1101_2 to decimal. 1×23 +1×22 +0×21 +1×20 = 1310 1×23+1×22+0×21+1×20=1310 Decimal to Binary: Divide the decimal number by 2, record the remainder, and repeat until the quotient is 0. Example: Convert 29_{10} to binary. Result: 11101_2 Hexadecimal to Binary: Replace each hexadecimal digit with its 4-bit binary equivalent. Example: Convert A3F_{16} to binary. Result: 101000111111_2 Example Question: Q: Convert the hexadecimal number 1F3 to binary and decimal. 5. Character Codes ASCII (American Standard Code for Information Interchange): Definition: A 7-bit character code representing English characters, digits, and symbols. Example: The ASCII code for A is 65. Unicode: Definition: A character encoding standard that represents characters from virtually all languages, using up to 32 bits. Example: The Unicode for A is U+0041. Example Question: Q: Explain the difference between ASCII and Unicode and provide an example of when each is used. 6. Signed Magnitude Arithmetic Definition: Arithmetic operations performed using the signed magnitude representation. Addition Example: +5+5 (as 00000101) + −3−3 (as 10000011). The result is found by subtracting magnitudes and applying the sign bit. Subtraction Example: Subtraction Example: Subtract 00001010 (+10) from 00001101 (+13). Result: 00000011 (+3). Example Question: Q: Perform the addition of +7 and -3 using signed magnitude representation. 7. One’s Complement Arithmetic Definition: Arithmetic operations performed using one’s complement representation. Addition Example: Add +5 (as 00000101) and -3 (as 11111100). Perform binary addition and apply end-around carry if necessary. Subtraction Example: Subtraction Example: Subtract 00001010 (10) from 11110101 (-10 in one’s complement). Result: 00011101. Example Question: Q: Perform the subtraction of -7 from +5 using one’s complement arithmetic. 8. Two’s Complement Arithmetic Definition: Arithmetic operations performed using two’s complement representation. Addition Example: Add +5 (as 00000101) and -3 (as 11111101). Perform binary addition, the result is 00000010. Subtraction Example: Subtraction Example: Subtract 00001101 (13) from 00000110 (6). Result: 11111111 (which is -1 in two’s complement). Example Question: Q: Perform the addition of +6 and -10 using two’s complement arithmetic. 9. Floating-Point Arithmetic Addition Example: Align the exponents and then add the significands (mantissa). Example: Add 1.25×101 1.25×101 and 2.75×100 2.75×100. Subtraction Example: Align the exponents, subtract the significands, and adjust the result. Example: Subtract 3.5×102 3.5×102 from 7.25×101 7.25×101. Example Question: Q: Perform the addition of 3.5×102 3.5×102 and 1.25×101 1.25×101 using floating-point arithmetic. 10. Error Detection and Correction Parity Bits: Definition: A simple error detection method where a parity bit is added to ensure the total number of 1-bits is even (even parity) or odd (odd parity). Example: For the byte 1010101, an even parity bit would be 0, making it 10101010. Hamming Code: Definition: An error-correcting code that can detect and correct single-bit errors. Example: For the data 1011, Hamming code would add redundancy bits to create an error-correcting code like 1011010. CRC (Cyclic Redundancy Check): Definition: A method of error detection where a fixed-length checksum is computed based on the data. Example: A CRC is calculated for data frames in network communications to detect errors. Example Question: Q: Explain how a parity bit can be used to detect errors in data transmission. Summary This lecture covers the fundamental concepts of computer arithmetic, including binary operations, signed integer representation, floating-point representation, conversions between number bases, character codes, arithmetic operations using signed magnitude, one’s complement, two’s complement, and error detection and correction techniques. Understanding these concepts is crucial for ensuring the accuracy and reliability of computations in digital systems. Example Questions and Answers 1. Q: Convert the binary number 11010 to decimal. A: 26 2. Q: Represent -12 in an 8-bit system using two’s complement representation. A: 11110100 3. Q: Explain how floating-point numbers are represented in IEEE 754 single precision format. A: Floating-point numbers are represented with 1 sign bit, 8 exponent bits, and 23 mantissa bits. 4. Q: Perform the addition of +6 and -10 using two’s complement arithmetic. A: 11111100 (which is -4 in decimal) 5. Q: How does the Hamming code detect and correct errors? A: Hamming code adds redundancy bits to the data to detect and correct single-bit errors.