nguyen le cs147. 2.4 signed integer representation 2.4.1 – signed magnitude 2.4.2 –…

18
Nguyen Le CS147

Upload: howard-crawford

Post on 20-Jan-2018

221 views

Category:

Documents


0 download

DESCRIPTION

Unsigned integer representation   carries   

TRANSCRIPT

Page 1: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Nguyen LeCS147

Page 2: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

2.4 Signed Integer Representation 2.4.1 – Signed Magnitude 2.4.2 – Complement Systems 2.4.3 – Unsigned Versus Signed Numbers 2.4.4 – Computers, Arithmetic, and Booth’s

Algorithm 2.4.5 – Carry Versus Overflow

Section overview

Page 3: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Unsigned integer representation

1 1 1 1 carries 0 1 0 1 1 1 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 1 1

Page 4: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

3 methods of representation

Signed magnitude

One’s complement Two’s complement

Page 5: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Signed magnitude

Signed magnitude representation includes a sign as the first bit of the storage location. A “1” in the high-order bit (or left-most bit) indicates a negative number and the rest of the remaining bits represent the number itself.

Ex: +1 and -1 in an 8-bit word would be 0 0 0 0 0 0 0 1 (+1) 1 0 0 0 0 0 0 1 (-1)

Page 6: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Signed magnitude addition

1 1 1 1 carries 0 1 0 0 1 1 1 1 0 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0

Page 7: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Overflow Overflow in signed numbers occurs when the sign of

the result is incorrect. The sign bit is used only for the sign, so we can’t carry into it.

1 1 1 1 1 carries 0 1 0 0 1 1 1 1 (79) 0 1 1 0 0 0 1 1 (99) 0 0 1 1 0 0 1 0 (50)

79 + 99 =/= 50

Page 8: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Signed magnitude subtraction

Page 9: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

One’s compliment

1 1 1 1 1 1 carries 0 0 0 1 0 1 1 1 (23) 1 1 1 1 0 1 1 0 (-9) 0 0 0 0 1 1 0 1 + 1 0 0 0 0 1 1 1 0 (14)

Flip the bits for all negative numbers.The last carry is added to the sum.

Page 10: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Two’s compliment

0 0 0 0 1 0 0 1 (9) 1 1 1 0 1 0 0

1 (-23) 1 1 1 1 0 0 1

0 (-14)

Flip the bits for all negative numbers.Add 1.

23 = 00010111-23 = 11101000 + 1 = 11101001

Page 11: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

2.6 Character Codes 2.6.1 – Binary-Coded Decimal 2.6.2 – EBCDIC 2.6.3 – ASCII 2.6.4 – Unicode

Section overview

Page 12: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Character codes

We’ve gone over how digital computers use the binary system to represent and manipulate numeric values, but have yet to consider how these internal values can be converted to a form that is meaningful to humans. This is done through a coding system used by the computer and how the values are stored and retrieved.

Page 13: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

BCD

Binary Coded Decimal (BCD) is very common in electronics, particularly those that display numerical data, such as alarm clocks and calculators.

4-bit binary form later extended to 6 1265 = 0000 0001 0010 0110 0101

1101

Page 14: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

EBCDIC

Extended Binary Coded Decimal Interchange Code (EBCDIC) used in IBM mainframe and midrange computer systems

8-bit binary form 1265 = 1111 0001 1111 0010 1111

0110 1101 0101

Page 15: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…
Page 16: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

ASCII

The American Standard Code for Information Interchange (ASCII) was created to better transmit data between systems.

Defines codes for 32 control characters, 10 digits, 52 letters (upper and lower-case), 32 special characters, and more.

Page 17: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…
Page 18: Nguyen Le CS147.  2.4 Signed Integer Representation  2.4.1 – Signed Magnitude  2.4.2 –…

Unicode

16-bit base coding with the capacity to encode the majority of characters used in every language of the world.

Unicode also defines an extension mechanism that will allow for the coding of an additional million characters.

Default character set of the Java programming language.