[go: up one dir, main page]

0% found this document useful (0 votes)
16 views48 pages

Chapter 2 Data Representation

Chapter 2 of CSC10009 covers data representation in computer systems, focusing on integer representation, arithmetic operations, and floating-point numbers. It explains various number systems, conversion methods, and the IEEE-754 standard for floating-point representation. Additionally, it discusses character encoding through ASCII and provides references for further reading.

Uploaded by

phknguyen2419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views48 pages

Chapter 2 Data Representation

Chapter 2 of CSC10009 covers data representation in computer systems, focusing on integer representation, arithmetic operations, and floating-point numbers. It explains various number systems, conversion methods, and the IEEE-754 standard for floating-point representation. Additionally, it discusses character encoding through ASCII and provides references for further reading.

Uploaded by

phknguyen2419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

CSC10009 – Computer Systems

Chapter 2
Data Representation

Instructor: Vu Thi My Hang, Ph.D.


TA: Le Quoc Hoa, M.Sc.

4.0
fit@hcmus
4.0
fit@hcmus
Outline

▪ Integer Representation
▪ Integer Arithmetic
▪ Floating Point
▪ Character

2
4.0
fit@hcmus
Outline

▪ Integer Representation
▪ Integer Arithmetic
▪ Floating Point
▪ Character

3
4.0
fit@hcmus
(Positional) Number Systems
▪ General formular for unsigned integer with n digits in q-base system
xn-1: MSB x0: LSB
(Most Significant Bit) (Less Significant Bit)

Value Exponential Form

Binary number system (base-2)


Octal number system (base-8)
Decimal number system (base-10)
Hexadecimal number system (base-16)

4
4.0
fit@hcmus
(Positional) Number Systems (2)
▪ Decimal number

▪ Binary number

▪ Hexadecimal number

5
4.0
fit@hcmus
(Positional) Number Systems (3)

6
4.0
fit@hcmus
Converting Binary ó Decimal
▪ Decimal è Binary

▪ Binary è Decimal

7
4.0
fit@hcmus
Converting Hexadecimal ó Decimal
▪ Decimal è Hexadecimal
Quotient Remainder
123/16 = 7 12 (B)

7/16 =0 7 è 12310 = 7B16

▪ Hexadecimal è Decimal

8
4.0
fit@hcmus
Converting Hexadecimal ó Binary
▪ Hexadecimal ó Binary

9
4.0
fit@hcmus
Integer Representation
▪ Unsigned integer A of n-bit:

▪ Signed integer A of n-bit in Sign/Magnitude representation:


an-1(MSB): Sign
0: positive number
1: negative number
an-2 … a0: Magnitude

-2n-1+1 2n-1-1 2n-1

2 zeros: +0/-0

10
4.0
fit@hcmus
Integer Representation (2)
▪ Signed integer A of n-bit in 2’s Complement representation:

if A >= 0

an-1(MSB): 0 à Positive number


if A < 0 an-1(MSB): 1 à Negative number

-2n-1 2n-1-1 2n-1

11
4.0
fit@hcmus
Integer Representation (3)
▪ Signed integer A of n-bit in 2’s Complement representation:

12
4.0
fit@hcmus
Integer Representation (4)

13
4.0
fit@hcmus
Integer Representation (5)
▪ Signed integer A of n-bit in Bias (Excess-k) representation:
Ø Choose K (a positive integer) to allows operations on the biased
numbers to be the same as for unsigned integers but represents both
positive and negative values. K is usually 2n-1 - 1 or 2n-1.
Ø Positive number: N > K with the absolute value (N – K).
Ø Negative number: N < K with the absolute value (K - N).

▪ E.g.: n = 8; K = 2n-1 -1 = 127


100000012 with unsigned value is 129 (greater than K)
è Positive number
è Absolute value: 129 – 127 = 210

14
4.0
fit@hcmus
Integer Representation (6)

15
4.0
fit@hcmus
Sign Extension
▪ Positive number 16-bit to 32-bit

▪ Negative number 16-bit to 32-bit

16
4.0
fit@hcmus
Outline

▪ Integer Representation
▪ Integer Arithmetic
▪ Floating Point
▪ Character

18
4.0
fit@hcmus
Logic Operation

19
4.0
fit@hcmus
Logic Operation (2)

20
4.0
fit@hcmus
Shift & Rotate

21
4.0
fit@hcmus
Shift & Rotate (2)

or

22
4.0
fit@hcmus
Shift & Rotate (3)

Clear a bit (AND with 0 is always 0)


Set a bit (OR with 1 is always 1)
Flip a bit (XOR with 1 = flip that bit)

: Get the value at bit i of x


: Set bit i of x to 1
: Set bit i of x to 0
: Flip bit i of x

23
4.0
fit@hcmus
Negation
▪ Negation operation ó Two complement operation

24
4.0
fit@hcmus
Addition
▪ General Rule

▪ Example

25
4.0
fit@hcmus
Addition (2)

OVERFLOW RULE: If two numbers are added, and they are both positive or both
negative, then overflow occurs if and only if the result has the opposite sign.

26
4.0
fit@hcmus
Subtraction
▪ General Rule
A – B = A + (-B) = A + (2’s Complement of B)

▪ Example

27
4.0
fit@hcmus
Subtraction (2)

OVERFLOW RULE: If two numbers are added, and they are both
positive or both negative, then overflow occurs if and only if the
28
result has the opposite sign.
4.0
fit@hcmus
Multiplication
▪ General Rule

▪ Example

29
4.0
Multiplication (2)
fit@hcmus (Unsigned Number)

A – B = A + (-B) = A + (2’s Complement of B)

30
4.0
Multiplication (3)
fit@hcmus (Signed Number: Booth’s Algorithm)

31
4.0
Division
fit@hcmus (Unsigned Number) Q=7, M = 3

32
4.0
Division (2)
fit@hcmus (Signed Number)

T = Q/M; R = Q%M
Q = 7, M = 3 è T = 2, R = 1
Q = 7, M = -3 è T = -2, R = 1
Q = -7, M = 3 è T = -2, R = -1
Q = -7, M = -3 è T = 2, R = -1

Q M T R
>0 >0 >0 >0
>0 <0 <0 >0
<0 >0 <0 <0
<0 <0 >0 <0

33
4.0
fit@hcmus
Outline

▪ Integer Representation
▪ Integer Arithmetic
▪ Floating Point
▪ Character

34
4.0
fit@hcmus
Fixed-point Numbers
▪ Representation

Integer part Fraction part

▪ Convert decimal è binary

35
4.0
fit@hcmus
Fixed-point Numbers (2)

Integer part Fraction part

123.37510 = 0111 1011.0110 00002


13.62510 = 0000 1101.1012

36
4.0
fit@hcmus
Normalized Float Number

±1.F * 2E

Significand (Fraction) Exponent

37
4.0
fit@hcmus
Normalized Float Number (2)

±1.F * 2E

Significand (Fraction) Exponent

38
4.0
fit@hcmus
Overflow vs. Underflow

±1.F * 2E

Significand (Fraction) Exponent

§ Overflow: A positive exponent becomes too large to fit in the exponent field.
§ Underflow: A negative exponent becomes too large to fit in the exponent field.

39
4.0
fit@hcmus
IEEE-754 Standard

Format Sign Exponent Significand


32-bit 1 bit 8 bits 23 bits
64-bit 1 bit 11 bits 52 bits
128-bit 1 bit 15 bits 112 bits

▪ Sign: 1 (negative number), 0 (positive number)


▪ Exponent (Biased representation): Bias K = 2n-1 - 1
o Single Precision (32-bit) K = 127 à Exponent = E + 127
o Double Precision (64-bit) K = 1023 à Exponent = E + 1023
▪ Significand
o Represent the mantissa (fractional part after the binary point)
o Normalized form: 1.xxxxxx

40
4.0
fit@hcmus
IEEE-754 Standard (2)
Single Precision (32-bit)
X = -5.25 1 1000 0001 0101 0000 0000 0000 0000 000

Step 1: Convert X = -5.2510 to Binary


X = −5.2510 = −101.012
Step 2: Normalize to the form ±1.F × 2ᴱ
X = −5.2510 = −101.012 = −1.0101×22
Step 3: Floating Point Representation
• Negative number → Sign bit = 1
• Exponent (with bias K = 127) E = 2 + 127 = 12910 = 1000 00012
• Significand (fraction part) 0101 0000 0000 0000 0000 000

41
4.0
fit@hcmus
IEEE-754 Standard (3)
Single Precision (32-bit)
X = 12.625 0 1000 0010 1001 0100 0000 0000 0000 000

Step 1: Convert X = 12.62510 to Binary


X = 12.62510 = 1100.1012
Step 2: Normalize to the form ±1.F × 2ᴱ
X = 12.62510 = 1100.1012 = +1.100101×23
Step 3: Floating Point Representation
• Positive number → Sign bit = 0
• Exponent (with bias K = 127) E = 3 + 127 = 13010 = 1000 00102
• Significand (fraction part) 1001 0100 0000 0000 0000 000

42
4.0
fit@hcmus
IEEE-754 Standard (4)
Single Precision (32-bit)
X = -3050 1 1000 1010 0111 1101 0100 0000 0000 000

Step 1: Convert X = -5.2510 to Binary


X = −305010 = −1011 1110 10102
Step 2: Normalize to the form ±1.F × 2ᴱ
X = −305010 = −1011 1110 10102 = −1.01111101010×211
Step 3: Floating Point Representation
• Negative number → Sign bit = 1
• Exponent (with bias K = 127) E = 11 + 127 = 13810 = 1000 10102
• Significand (fraction part) 0111 1101 0100 0000 0000 000

43
4.0
fit@hcmus
IEEE-754 Standard (5)

44
4.0
fit@hcmus
IEEE-754 Standard (6)
Special numbers
Sign Exponent Significand (Fraction)
Zero 0 or 1 00…0 00…0
Denormalized 0 or 1 00…0 !=0
Plus Infinity (+∞) 0 11…1 00…0
Minus Infinity (-∞) 1 11…1 00…0
NaN 0 or 1 11…1 !=0

45
4.0
fit@hcmus
Outline

▪ Integer Representation
▪ Integer Arithmetic
▪ Floating Point
▪ Character

46
4.0
fit@hcmus
Character: ASCII
American Standard Code for Information Interchange

47
4.0
fit@hcmus
Reference
BOOKS
1. Computer Systems: A Programmers Perspective, Prentice Hall, 2016, Pearson.

2. Computer Organization and Design: The Hardware/Software Interface (5th ed),


D. A. Patterson and J. L. Hennessy, 2014, Morgan Kaufmann.

3. Computer Organization: A Quantitative Approach, Patterson and J. L.


Hennessy, 2017, Morgan Kaufmann.

4. Digital Design and Computer Architecture (2th ed), D.M Harris and S. L. Harris,
2013, Morgan Kaufmann.

48
4.0
fit@hcmus
4.0

Thank you for your


attention!

49

You might also like