binary negative integers. sign and magnitudesign and magnitude ones complementones complement twos...

34
Binary Binary Negative Integers

Upload: sofia-morse

Post on 26-Mar-2015

246 views

Category:

Documents


12 download

TRANSCRIPT

Page 1: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

BinaryBinaryNegative Integers

Page 2: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Negative Negative IntegersIntegers

• Sign and magnitudeSign and magnitude

• One’s complementOne’s complement

• Two’s complementTwo’s complement

• Binary Coded Decimal (BCD)Binary Coded Decimal (BCD)

Page 3: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Sign and Sign and MagnitudeMagnitude• The method used in decimal to represent The method used in decimal to represent

negative numbers is sign and negative numbers is sign and magnitude.magnitude.

- 25- 25SignSign

Magnitude/valueMagnitude/value

• This system is available in decimal This system is available in decimal where:where:

1 ≡ negative sign 1 ≡ negative sign

Page 4: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Sign and Sign and MagnitudeMagnitude• The method is as follows:The method is as follows:

– Convert the value or magnitude to binary Convert the value or magnitude to binary and represent using eight or ten bits or as and represent using eight or ten bits or as you are instructedyou are instructed

– Change the leftmost bit to 1 if the number Change the leftmost bit to 1 if the number is negativeis negative

Page 5: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Example:Example:• Represent the following decimal as Represent the following decimal as

binary, using sign and magnitude:binary, using sign and magnitude:

– NEGATIVE 10NEGATIVE 101010

– NEGATIVE 25NEGATIVE 251010

Page 6: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

-10 to Binary using 8 bit Sign and Magnitude

• Convert 10 to binary1010

Use 8 bits to represent00001010

Change to negative:110001010

-1010=100010102

2 10 Remainder

2 5 0

2 2 1

2 1 0

0 1

Page 7: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

-25 to Binary using 8 bit Sign and Magnitude

• Convert 25 to binary11001

Use 8 bits to represent00011001

Change to negative:110011001

-2510=100110012

2 25 Remainder

2 12 1

2 6 0

2 3 0

2 1 1

0 1

Page 8: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

One’s One’s ComplementComplement• The method is as follows:The method is as follows:

– Convert the value or magnitude to binary Convert the value or magnitude to binary and represent using eight or ten bits or as and represent using eight or ten bits or as you are instructedyou are instructed

– Find the complement by changing all the Find the complement by changing all the 0’s to 1’s and all the 1’s to 0’s0’s to 1’s and all the 1’s to 0’s

Page 9: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Example:Example:• Represent the following decimal as Represent the following decimal as

binary, using ONE’S COMPLEMENT:binary, using ONE’S COMPLEMENT:

– NEGATIVE 10NEGATIVE 101010

– NEGATIVE 25NEGATIVE 251010

Page 10: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

-25 to Binary using 8 bit One’s Complement

• Convert 25 to binary11001

Use 8 bits to represent00011001

Change to negative: 1 0 and; 0 111100110

-2510=111001102

2 25 Remainder

2 12 1

2 6 0

2 3 0

2 1 1

0 1

Page 11: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Two’s Two’s ComplementComplement• The method is as follows:The method is as follows:

– Convert the value or magnitude to binary Convert the value or magnitude to binary and represent using eight or ten bits or as and represent using eight or ten bits or as you are instructedyou are instructed

– Find the One’s complement by changing Find the One’s complement by changing all the 0’s to 1’s and all the 1’s to 0’sall the 0’s to 1’s and all the 1’s to 0’s

– Add one to the new valueAdd one to the new value

Page 12: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Example:Example:• Represent the following decimal as Represent the following decimal as

binary, using TWO’S COMPLEMENT:binary, using TWO’S COMPLEMENT:

– NEGATIVE 10NEGATIVE 101010

– NEGATIVE 25NEGATIVE 251010

Page 13: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

-25 to Binary using 8 bit Two’s Complement

• Convert 25 to binary11001

Use 8 bits to represent00011001

Find one’s complement 11100110

Add one to the answer11100110+1

-2510=111001112

2 25 Remainder

2 12 1

2 6 0

2 3 0

2 1 1

0 1

1 1 1 0 0 1 1 0

+ 1

1 1 1 0 0 1 1 1

Page 14: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Binary Coded Binary Coded DecimalDecimal

Page 15: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

FormatFormat•Each digit is converted Each digit is converted

separatelyseparately using four (4) using four (4) bits each.bits each.

2 2 Remainder

2 1 0

0 1

2= 0010

2 5 Remainder

2 2 1

2 1 0

0 1

5=0101

Page 16: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

FormatFormat•Decimal positioning is Decimal positioning is

keptkept

Page 17: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Negative BCDNegative BCD•Use Sign and Magnitude Use Sign and Magnitude

where the signs are:where the signs are:

Page 18: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Positive and Positive and NegativeNegative

Page 19: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Steps:Steps:

•Convert each digit to binaryConvert each digit to binary•Write sign (if necessary)Write sign (if necessary)•Write answer in decimal orderWrite answer in decimal order

Convert the following numbers from decimal to Convert the following numbers from decimal to binary using BCD format:binary using BCD format:

1010 250250 4343 1111 5454-10-10 +250+250 -43-43 +11+11 -54-54

Page 20: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

BinaryBinaryReal NumbersReal Numbers

Page 21: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Real NumbersReal Numbers• Real numbers are numbers containing Real numbers are numbers containing

fractions. fractions.

• There are two ways real numbers are There are two ways real numbers are represented in binary. represented in binary.

• They are:They are:• Fixed-point numbersFixed-point numbers• Floating-point numbersFloating-point numbers

Page 22: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Fixed-point Fixed-point NumbersNumbers• Decide the number of places after the Decide the number of places after the

point because the point is not stored point because the point is not stored among the digits.among the digits.

• Convert the whole number to binaryConvert the whole number to binary

• Convert the fraction to binary:Convert the fraction to binary:– Multiply the fraction by two and record the Multiply the fraction by two and record the

any resulting whole numberany resulting whole number– Repeat until you get the set amount of Repeat until you get the set amount of

places after the pointplaces after the point

Page 23: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Fixed-point Fixed-point NumbersNumbers• Convert 4.2Convert 4.21010 to binary with 4 places after the to binary with 4 places after the

point.point.

• The answer is therefore:The answer is therefore:1001000011001122

2 4 R

2 2 0

2 1 0

0 1

=100

0.2 x 2 = 0.4

0.4 x 2 = 0.8

0.8 x 2 = 1.6

0.6 x 2 = 1.2

=0011

Page 24: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Floating-point Floating-point NumbersNumbers• The number of places after the point The number of places after the point

varies.varies.

• Data is represented in the following Data is represented in the following parts:parts:– A signA sign– A fractional part (example 0.345) or A fractional part (example 0.345) or

mantissamantissa– The baseThe base– An exponentAn exponent

Page 25: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Standard FormStandard Form

• Change to standard form:Change to standard form:345345

-45.6-45.6

Page 26: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Floating-point Floating-point NumbersNumbers• Decimal Example:Decimal Example:

• This is equal to writing a number in standard This is equal to writing a number in standard formform

Page 27: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Floating-point Floating-point NumbersNumbers• Binary Example: Binary Example:

Binary number 11111010Binary number 11111010

• The mantissa is a binary fractionThe mantissa is a binary fraction• The sign bit : 1 for negative and 0 for positiveThe sign bit : 1 for negative and 0 for positive• This exponent uses sign and magnitudeThis exponent uses sign and magnitude

11 111111 10101010

SSign EExponent MMantissa

Page 28: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Floating-point Floating-point NumbersNumbers• IEEE Standard uses 32 and 64bits, but for IEEE Standard uses 32 and 64bits, but for

simplicity we will use only 8 bits as follows:simplicity we will use only 8 bits as follows:– The sign – 1 bitThe sign – 1 bit

• 1 means negative; 0 means positive1 means negative; 0 means positive

– The Exponent – 3 bitsThe Exponent – 3 bits• Sign and magnitude. Leftmost bit is the signSign and magnitude. Leftmost bit is the sign

– The Mantissa – 4 bitsThe Mantissa – 4 bits• A fractionA fraction

Page 29: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

From Decimal: From Decimal: 3¾3¾

1.1. Convert the decimal to Convert the decimal to binary (maintain the binary (maintain the whole and fraction whole and fraction parts).parts).

2.2. Normalise the Normalise the mantissamantissa

3.3. Convert the resulting Convert the resulting exponentexponent

4.4. Insert the sign bitInsert the sign bit

5.5. Write the number in Write the number in SEM formatSEM format

1.1. 3 ¾ to binary retaining 3 ¾ to binary retaining decimal format: 11.11decimal format: 11.11

2.2. Normalised mantissa Normalised mantissa as if in standard as if in standard form: .1111x2form: .1111x222

3.3. The exponent : 2 = 011The exponent : 2 = 011

4.4. The number is The number is positive, so the sign = positive, so the sign = 00

5.5. RESULT:0 011 1111RESULT:0 011 111122

Page 30: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Let us Calculate:Let us Calculate:• Binary Example: Binary Example:

111110101111101022

• The mantissa : 0.625The mantissa : 0.625• The sign bit : - (negative)The sign bit : - (negative)• The exponent : -3The exponent : -3• RESULT: - 0.1010 X 2RESULT: - 0.1010 X 2-3-3

11 111111 10101010SignSign ExponentExponent MantissaMantissa

- -3 0.625

22-1-1 22-2-2 22-3-3 22-4-4

1 0 1 0.5.5 0.1250.125

= 0.5 + 0.125

Page 31: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Let us Calculate:Let us Calculate:• Binary Example: 11111010Binary Example: 1111101022

• The mantissa is: 0.625The mantissa is: 0.625• The sign bit : - (negative)The sign bit : - (negative)• The exponent : -3The exponent : -3• RESULT: - 0.1010 X RESULT: - 0.1010 X 22-3-3

= -0 0 0 0.1 0 1 0= -0 0 0 0.1 0 1 0

=-0.0001=-0.000122

= - 0.0625= - 0.06251010

Page 32: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

CharactersCharacters• ASCII (American Standard Code of ASCII (American Standard Code of

Information Interchange)Information Interchange)

• EBCDIC (Extended Binary Coded EBCDIC (Extended Binary Coded Decimal Interchange CodeDecimal Interchange Code

Page 33: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

Parity BitParity Bit• To maintain data integrity a special To maintain data integrity a special

signal bit is sometimes used. This is a signal bit is sometimes used. This is a parity bit. Instead of the regular eight parity bit. Instead of the regular eight bits that make up the byte, nine bits are bits that make up the byte, nine bits are used.used.

• If he number of “1” bits is odd then the If he number of “1” bits is odd then the parity is set to 1 so that the number of parity is set to 1 so that the number of 1”s is always even1”s is always even

• If the number of “1” bits is even the If the number of “1” bits is even the parity is set to “0”.parity is set to “0”.

Page 34: Binary Negative Integers. Sign and magnitudeSign and magnitude Ones complementOnes complement Twos complementTwos complement Binary Coded Decimal (BCD)Binary

The END