Binary
E N D
Presentation Transcript
Binary Negative Integers
Negative Integers • Sign and magnitude • One’s complement • Two’s complement • Binary Coded Decimal (BCD)
Sign and Magnitude • The method used in decimal to represent negative numbers is sign and magnitude. - 25 Sign Magnitude/value • This system is available in decimal where: 1 ≡ negative sign
Sign and Magnitude • The method is as follows: • Convert the value or magnitude to binary and represent using eight or ten bits or as you are instructed • Change the leftmost bit to 1 if the number is negative
Example: • Represent the following decimal as binary, using sign and magnitude: • NEGATIVE 1010 • NEGATIVE 2510
-10 to Binary using 8 bit Sign and Magnitude • Convert 10 to binary • 1010 • Use 8 bits to represent • 00001010 • Change to negative: • 10001010 • -1010=100010102
-25 to Binary using 8 bit Sign and Magnitude • Convert 25 to binary • 11001 • Use 8 bits to represent • 00011001 • Change to negative: • 10011001 • -2510=100110012
One’s Complement • The method is as follows: • Convert the value or magnitude to binary and represent using eight or ten bits or as you are instructed • Find the complement by changing all the 0’s to 1’s and all the 1’s to 0’s
Example: • Represent the following decimal as binary, using ONE’S COMPLEMENT: • NEGATIVE 1010 • NEGATIVE 2510
-25 to Binary using 8 bit One’s Complement • Convert 25 to binary • 11001 • Use 8 bits to represent • 00011001 • Change to negative: 1 0 and; 0 1 • 11100110 • -2510=111001102
Two’s Complement • The method is as follows: • Convert the value or magnitude to binary and represent using eight or ten bits or as you are instructed • Find the One’s complement by changing all the 0’s to 1’s and all the 1’s to 0’s • Add one to the new value
Example: • Represent the following decimal as binary, using TWO’S COMPLEMENT: • NEGATIVE 1010 • NEGATIVE 2510
-25 to Binary using 8 bit Two’s Complement • Convert 25 to binary • 11001 • Use 8 bits to represent • 00011001 • Find one’s complement • 11100110 • Add one to the answer • 11100110+1 • -2510=111001112
Binary Coded Decimal B.C.D.
Format • Each digit is converted separately using four (4) bits each. 25 0010 0101
Format • Decimal positioning is kept 25 = 0010 0101 2 10
Negative BCD • Use Sign and Magnitude where the signs are: + Positive = 1110 2 - Negative = 1111 2
Positive and Negative +25 = 11100010 0101 2 -25 = 11110010 0101 2
Steps: • Convert each digit to binary • Write sign (if necessary) • Write answer in decimal order Convert the following numbers from decimal to binary using BCD format: 10 250 43 11 54 -10 +250 -43 +11 -54
Binary Real Numbers
Real Numbers • Real numbers are numbers containing fractions. • There are two ways real numbers are represented in binary. • They are: • Fixed-point numbers • Floating-point numbers
Fixed-point Numbers • Decide the number of places after the point because the point is not stored among the digits. • Convert the whole number to binary • Convert the fraction to binary: • Multiply the fraction by two and record the any resulting whole number • Repeat until you get the set amount of places after the point
Fixed-point Numbers • Convert 4.210 to binary with 4 places after the point. • The answer is therefore:10000112
Floating-point Numbers • The number of places after the point varies. • Data is represented in the following parts: • A sign • A fractional part (example 0.345) or mantissa • The base • An exponent
Standard Form • Change to standard form: • 345 • -45.6
Floating-point Numbers • Decimal Example: • This is equal to writing a number in standard form 3 345 = 0.345 x 10 Exponent Sign Mantissa base 2 -45.6 = -0.456 x 10
Floating-point Numbers • Binary Example: Binary number 11111010 • The mantissa is a binary fraction • The sign bit : 1 for negative and 0 for positive • This exponent uses sign and magnitude
Floating-point Numbers • IEEE Standard uses 32 and 64bits, but for simplicity we will use only 8 bits as follows: • The sign – 1 bit • 1 means negative; 0 means positive • The Exponent – 3 bits • Sign and magnitude. Leftmost bit is the sign • The Mantissa – 4 bits • A fraction
Convert the decimal to binary (maintain the whole and fraction parts). Normalise the mantissa Convert the resulting exponent Insert the sign bit Write the number in SEM format 3 ¾ to binary retaining decimal format: 11.11 Normalised mantissa as if in standard form: .1111x22 The exponent : 2 = 011 The number is positive, so the sign = 0 RESULT:0 011 11112 From Decimal: 3¾
Let us Calculate: • Binary Example: 111110102 • The mantissa : 0.625 • The sign bit : - (negative) • The exponent : -3 • RESULT: - 0.1010 X 2-3 = 0.5 + 0.125
Let us Calculate: • Binary Example: 111110102 • The mantissa is: 0.625 • The sign bit : - (negative) • The exponent : -3 • RESULT: - 0.1010 X 2-3 = -0 0 0 0.1 0 1 0 =-0.00012 = - 0.062510
Characters • ASCII (American Standard Code of Information Interchange) • EBCDIC (Extended Binary Coded Decimal Interchange Code
Parity Bit • To maintain data integrity a special signal bit is sometimes used. This is a parity bit. Instead of the regular eight bits that make up the byte, nine bits are used. • If he number of “1” bits is odd then the parity is set to 1 so that the number of 1”s is always even • If the number of “1” bits is even the parity is set to “0”.