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

Post on 20-Jan-2018

220 views 0 download

description

Unsigned integer representation   carries   

transcript

Nguyen LeCS147

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

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

3 methods of representation

Signed magnitude

One’s complement Two’s complement

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)

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

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

Signed magnitude subtraction

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.

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

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

Section overview

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.

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

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

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.

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.