Top Banner
Lecture 4: Number Systems (Chapter 3) (1) Data Types Section 3-1 (2) Complements Section 3-2 (3) Fixed Point Representations Section 3-3 (4) Floating Point Representations Section 3-4 (5) Other Binary Codes Section 3-5 (6) Error Detection Codes Section 3-6
22

Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Jan 12, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Lecture 4: Number Systems (Chapter 3)

(1) Data Types Section 3-1

(2) Complements Section 3-2

(3) Fixed Point Representations Section 3-3

(4) Floating Point Representations Section 3-4

(5) Other Binary Codes Section 3-5

(6) Error Detection Codes Section 3-6

Page 2: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Data Types

Information that a Computer is dealing with:

DataNumeric Data

Numbers (Integer, real)Non-numeric Data

Letters, Symbols

Relationship between data elementsData Structures

Linear Lists, Trees, Rings, etc

Program (Instructions)

Page 3: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Data Types: Numeric Data Representation

Nonpositional number systemRoman number system

Positional number systemEach digit position has a value called a weight associated with itExamples: Decimal, Octal, Hexadecimal, Binary

Base (or radix) R numberUses R distinct symbols for each digit

Example A R = a n-1 a n-2 ... a 1 a 0 .a -1 …a -m

V(A R) = SUM (a k * R k) for k = -m to n-1

R = 10 Decimal number systemR = 2 BinaryR = 8 OctalR = 16 Hexadecimal

Page 4: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Data Types: Numeric Data Representation

Why a Positional Number System for Digital Computers???

Major Consideration is the COST and TIMECost of building hardware

Arithmetic and Logic Unit, CPU,CommunicationsTime to processing

Arithmetic - Addition of Numbers - Table for AdditionNon-positional Number System

Table for addition is infinite--> Impossible to build, very expensive even if it can be built

Positional Number SystemTable for Addition is finite--> Physically realizable, but cost wise the smaller the table size, the less expensive--> Binary is favorable to Decimal

Page 5: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Unsigned binary numbers are typically used to represent computer addresses or other values that are guaranteed not to be negative.

An n-bit unsigned binary integer A = an-1 an-2... a1 a0

has a value of

For example,

1011 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20

= 8 + 2 + 1 = 11

An n-bit unsigned binary integer has a range from 0 to 2n - 1.

Positive (Unsigned) Binary Numbers

ii

n

i

a 21

0

Page 6: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Octal and Hexadecimal Numbers

Octal, base-8, numbers were used in the early days of computing to represent binary numbers

Octal numbers are made by grouping binary numbers together three bits at a time

Hexadecimal, base-16, numbers are the representation of choice today

Hex numbers are made by grouping binary numbers together four bits at a time

For example:Octal: 7 2 5 1 7 5 2 2 .Binary: 1 1 1 0 1 0 1 0 1 0 0 1 1 1 1 1 0 1 0 1 0 0 1 0Hex: E A 9 F 5 2

Page 7: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Negative (Signed) Binary Numbers

Positional representation using n bits

X = X n X n-1 X n-2 … X 1 X 0 . X -1 X -2 ... X -m

Sign-magnitude formatLeft most bit position (X n) is the sign bit -- only bit that is complemented

0 for positive number1 for negative number

Remaining n-1 bits represent the magnitudeMin: - (2 n - 2 -m) = 1111 1111 . 1111 1111Max: + (2 n - 2 -m) = 0111 1111 . 1111 1111Zero: - 0 = 1000 0000 . 0000 0000Zero: +0 = 0000 0000 . 0000 0000

Page 8: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Complements of Numbers

Two types of complements for base R number system:R’s complement (R-1)’s complement

The (R-1)’s ComplementSubtract each digit of a number from (R-1)

Examples:9’s complement of 835 10 is 164 10

1’s complement of 1010 2 is 0101 2

(bit by bit complement operation)

The R’s ComplementAdd 1 to the low-order digit of its (R-1)’s complement

Examples:10’s complement of 835 10 is 164 10 + 1 = 165 10

2’s complement of 1010 2 is 0101 2 + 1 = 0110 2

Page 9: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Negative (Signed) Binary Numbers

Ones complement formatNegative numbers are represented by a bit-by-bit complementation of the (positive) magnitude (the process of negation)

Sign bit interpreted as in sign-magnitude format

Examples (8-bit words):+42 = 0 00101010-42 = 1 11010101

Min: - (2 n - 2 -m) = 1111 1111 . 1111 1111Max: + (2 n - 2 -m) = 0111 1111 . 1111 1111Zero: - 0 = 1111 1111 . 1111 1111Zero: +0 = 0000 0000 . 0000 0000

Page 10: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Negative (Signed) Binary Numbers

Twos complement formatNegative numbers, -X, are represented by the pseudo- positive number: 2n - |X|

An n-bit unsigned binary integer A = an-1 an-2... a1 a0 has a value of

For example: 1011 = -1 x 23 + 0 x 22 + 1 x 21 + 1 x 20

= -8 + 2 + 1 = -5

With 2n digits:2 n-1 -1 positive numbers2 n -1 negative numbers

Given the representation for +X, the representation for -X is found by taking the 1s complement of +X and adding 1

ii

n

i

nn aa 22

2

0

11

Page 11: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Negative (Signed) Binary Numbers

Twos complement format

Most significant bit is the “sign bit”.

Number representation is not symmetric.

Only one representation for zero.

Easy to negate, add, and subtract numbers.

A little bit trickier for multiply and divide.

Min: - (2 n) = 1000 0000 . 0000 0000

Max: + (2 n - 2 -m) = 0111 1111 . 1111 1111

Zero: = 0000 0000 . 0000 0000

Page 12: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Signed 2’s Complement Addition

Add the two numbers, including their sign bit, and discard any carry out of left-most(sign) bit

Examples: 6 0 0110 -6= 1 1010+ 9 0 1001 + 9= 0 1001 15 0 1111 3= 0 0011

6 0 0110 -9 1 0111+ -9 1 0111 + -9 1 0111 -3 1 1101 -18 (1) 0 1110

9 0 1001+ 9 0 1001 18 1 0010

Page 13: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Detecting 2’s Complement Overflow

When adding two's complement numbers, overflow will only occur if the numbers being added have the same sign the sign of the result is different

If we perform the addition an-1 an-2 ... a1 a0

+ bn-1bn-2… b1 b0

----------------------------------

= sn-1sn-2… s1 s0

Overflow can be detected as

where cn-1and cn are the carry in and carry out of the most significant bit.

1 nn ccV

Page 14: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Signed 2’s Complement Subtraction

To subtract two's complement numbers we first negate the second number and then add the corresponding bits of both numbers.

Examples:

3 = 0011 -3 = 1101 -3 = 1101 3 = 0011- 2 = 0010 - -2 = 1110 - 2 = 0010 - -2 = 1110

become:

3 = 0011 -3 = 1101 -3 = 1101 3 = 0011+ -2 = 1110 + 2 = 0010 + -2 = 1110 + 2 = 0010

1 = 0001 -1 = 1111 -5 = 1011 5 = 0101

Page 15: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Sign-Extension / Zero-Extension

Sign-extension is used for signed immediates and signed values from memory

To sign-extend an n bit number to n+m bits, copy the sign-bit m times.

For example, with n = 4 and m = 4,

1011 = -4 0101 = 5

11111011 = -4 00000101 = 5

Zero-extension is used for logical operations and unsigned values from memory

To zero-extend an n bit number to n+m bits, copy zero m times.

For example, with n = 4 and m = 4,

1011 = 11 0101 = 5

00001011 = 11 00000101 = 5

Page 16: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Floating Point Number Representation

The location of the fractional point is not fixed to a certain location

--> The range of the representable numbers is wide

--> high precision

F = EM

m n e k e k-1 ... e 0 m n-1 m n-2 ... m 0 . m -1 ... m -m

sign exponent mantissa

Mantissa

Signed fixed point number, either an integer or a fractional number

Exponent

Designates the position of the radix point

Page 17: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Floating Point Number Representation

Decimal Value:

V = M * R E

Where: M= Mantissa

E= Exponent

R= Radix (10)

Example (decimal):

1234.5678

Exponent Mantissa

Sign Value Sign Value

0 4 0 0.12345678

==> 0.12345678 x 10 +4

Page 18: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Floating Point Number Representation

Example (binary):

+ 1001.11 (= 9.75)

Make a fractional number, counting the number of shifts:

+ .100111 ==> 4 shifts

Exponent Mantissa

Sign Value Sign Value

0 100 0 1001111

Or for a 16-bit number with a sign, 5-bit exponent, 10-bit mantissa:

0 00100 1001111000

Page 19: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Other Representations- Gray Codes

Characterized by having their representations of the binary integers different in only one digit between consecutive integers

Useful in analog-digital conversion.

Decimal Gray Binary Decimal Gray Binary

0 0 0 0 0 0 0 0 0 8 1 1 0 0 1 0 0 0

1 0 0 0 1 0 0 0 1 9 1 1 0 1 1 0 0 1

2 0 0 1 1 0 0 1 0 10 1 1 1 1 1 0 1 0

3 0 0 1 0 0 0 1 1 11 1 1 1 0 1 0 1 1

4 0 1 1 0 0 1 0 0 12 1 0 1 0 1 1 0 0

5 0 1 1 1 0 1 0 1 13 1 0 1 1 1 1 0 1

6 0 1 0 1 0 1 1 0 14 1 0 0 1 1 1 1 0

7 0 1 0 0 0 1 1 1 15 1 0 0 0 1 1 1 1

Page 20: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Other Representations- ASCII Characters

4MSBs3LSBs 0 1 1 3 4 5 6 70 (hex) NUL DLE SP 0 @ P ‘ p1 SOH DC1 ! 1 A Q a q 2 STX DC2 " 2 B R b r3 ETX DC3 # 3 C S c s4 EOT DC4 $ 4 D T d t5 ENQ NAK % 5 E U e u6 ACK SYN & 6 F V f v7 BEL ETB ’ 7 G W g w8 BS CAN ( 8 H X h x9 HT EM ) 9 I Y i yA LF SUB * : J Z j zB VT ESC + ; K [ k {C FF FS , < L \ l |D CR GS - = M ] m }E SO RS . > N ^ n ~F SI US / ? O _ o DEL

Page 21: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Error Detecting Codes- Parity

Parity SystemSimplest method for error detectionOne parity bit attached to the informationEven Parity and Odd Parity

Even ParityOne bit is attached to the information so that the total number of 1 bits is an even number

1011001 01010010 1 ==> B even = B n-1 (+) B n-2 (+) … B 0

Odd ParityOne bit is attached to the information so that the total number

of 1 bits is an odd number1011001 11010010 0 ==> B odd = B n-1 (+) B n-2 (+) … B 0 (+) 1

Page 22: Lecture 4: Number Systems (Chapter 3) (1) Data TypesSection3-1 (2) ComplementsSection3-2 (3) Fixed Point RepresentationsSection3-3 (4) Floating Point RepresentationsSection3-4.

Error Detecting Codes- Parity

B 0

B 1

B 2

B 3

B 4

B 5

B 6

B even

B 0

B 1

B 2

B 3

B 4

B 5

B 6

B even

ERROR

Even Parity Generator Circuit

Even Parity Checker Circuit