Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Computer Science Georgia State University

Similar presentations


Presentation on theme: "Department of Computer Science Georgia State University"— Presentation transcript:

1 Department of Computer Science Georgia State University
Data Manipulation Department of Computer Science Georgia State University

2 What will be covered? A review on binary notation Fractions in binary
Binary addition Storing integers Storing fractions

3 A review on binary notation
How to convert a binary into a decimal (base 10)? ( )2= ( ? )10

4 ( )2= ( ? )10 23 1 Position 4 3 2 1 Position’s quantity 24 23 22 21 20 16 8 4 2 1 ⨯ ⨯ ⨯ ⨯ ⨯ 1 = = 23

5 Fractions in Binary

6 Fractions in Binary Decimal Point

7 1 0 1 . 0 1 1 Fractions in Binary Radix Point Integer Part
Integer Part Fractional Part

8 ( )2= ( ? )10 1 . Position 2 1 -1 -2 -3 Position’s quantity 22 21 20 2-1 2-2 2-3 4 2 1 ⨯ ⨯ ⨯ ⨯ ½ ⨯ ¼ ⨯ ⅛ = ¼ + ⅛ = 5 ⅜

9 Practice 1 ( 1 0 . 0 1 1 )2= ( ? )10 ½ ¼ ⅛ Position 7 6 5 4 3 2 1 . -1
( )2= ( ? )10 Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8

10 Practice 1 ( )2= ( ? )10 Position's quantity 128 64 32 16 8 4 2 1 . + + 2 = 2⅝ ( )2= ( ½ + ⅛ )10=( 2⅝ ) 10

11 Binary Addition Base 2 Base 10 ? 5 8 ?

12 Binary Addition Base 10 1 5 8 5 8 2 7 8 5

13 Binary Addition Base 2

14 Binary Addition + 0 + 1 1 + 0 1 + 1 1 1 1 2

15 1 1 1 0 1 0 + 1 1 0 1 1 1 1 1 1 Binary Addition Integers Base 2 1 1 1
Integers 1 1 1 1

16 Binary Addition Base 2 Fractions 1 1 1 . 1

17 Storing Integers In the “real world” of mathematics, computers must represent both positive and negative binary numbers for positive and negative integers. For example, even when dealing with positive arguments, mathematical operations may produce a negative result. Example : = -5 Thus needs to be a consistent method of representing negative numbers in computers.

18 Storing Integers Sign-Magnitude The simplest conceptual format
Two’s complement The most popular system for representing integers within today’s computers. Excess notation Representing a fixed length binary number in computer circuits.

19 Sign-Magnitude Sign bit : leftmost bit
0 represents positive, 1 represents negative Magnitude : the remaining bits The same as binary notation of absolute value E.g. 4-bit sign-magnitude format But….... Sign Magnitude 0000 1000 +0 -0 E.g. Using 4-bit sign-magnitude format Calculate 110+(-1)10 +1 is stored as 0001 -1 is stored as 1001 0011 represents 3 1011 represents -3 0001 1010 = -210

20 Two’s complement notation
Definition: “The two’s complement of a binary integer is the 1’s complement of the number plus 1.” For each bit, change 0 to 1, and 1 to 0

21 Two’s complement notation
How to encode an integer in two’s complement notation? For positive integers, keep the binary representation For negative integers, Start with N-bit representation of their absolute values (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) “Complement and Add One”

22 Two’s complement notation
How to encode an integer in two’s complement notation? For positive integers, keep the binary representation. For negative integers, Start with N-bit representation of their absolute values (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) E.g. Represent in Two’s complement The positive integer: 610 Complement each bit: Add one: -610

23 Two’s complement notation
Another simple way to get the two’s complement notation for a negative integer “Copy until one and Complement” 6 Copy the bits from right to left until a 1 has been copied Complement the remaining bits 0  1 1  0 - 6

24 Two’s complement notation
Another simple way to get the two’s complement notation for a negative integer “Copy until one and Complement” The positive integer: Copy until 1 1 0 Complement remaining: -610 610 610 -610 The positive integer: Complement each bit: Add one: “Complement and Add one”

25 Two’s complement notation
E.g. Represent in Two’s complement using 4-bit pattern The positive integer: 410 Copy until 1: Complement remaining: -410 E.g. Represent in Two’s complement using 4-bit pattern The positive integer: 810 Copy until 1: Complement remaining: -810

26 Figure 1.19 Two’s complement notation systems
-4 ~ +3 -8 ~ +7

27 Two’s complement notation
Range of integers with Two’s complement 3-bit : ~ +3 4-bit : ~ +7 5-bit : ~ +15 8-bit : ~ +127 N-bit : ~ ~ ~ ~ -2N-1 ~ +2N-1-1 So In order to store value 8 in two’ complement notation, how many bits should be used at least?

28 Two’s complement notation
How to decode a Two’s complement notation? Check “Sign bit” Sign bit = 0 ( positive number) Convert the binary number to a decimal directly Sign bit = 1 ( negative number) Do the “ Copy until 1 and Complement ” process Convert binary into decimal E.g. Decode Two’s complement notation 1010 Two’s complement: Negative Copy until one: 1 0 Complement remaining: The positive integer: 610 Result: -610

29 Practice 2 Decode the following two’s complement (8-bit)

30 Practice 2 Decode the following two’s complement (8-bit) Complement Copy 1 0 = 1 *16 + 1*2 = 18 Final answer: - 18

31 Addition in Two’s Complement

32 Overflow problem 9 is not in range -8 ~ 7, thus error happened.
Problem in base ten Problem in 4-bit Two’s complement 5 + 4 Answer in base ten 9 -7 9 is not in range -8 ~ 7, thus error happened. We call this phenomenon as overflow.

33 Excess Notation Excess four conversion table 7 7 6 5 4 3 2 1

34 Storing Fractions Besides storing the binary representation, we need to store the position of radix. Radix Point One popular way to store fractions in computer is called floating-point notation.

35 Floating-point Notation
Scientific notation ±M x BE (M < 1) M is the mantissa, B is the exponent base (usually 2), and E is the exponent Normalized form E.g * 102 , * 22 , - 0.1* 2-3 8 bits Sign bit Exponent ( 3 bits) Mantissa ( 4 bits)

36 Error can be reduced by using a longer mantissa field
Truncation errors Encoding the value 2 ⅝ Error can be reduced by using a longer mantissa field

37 What you have learned ? Binary System Binary notation
Fractions in binary Binary addition How to store integers and fractions in computer? Two’s complement notation Overflow problem Floating point notation (scientific notation) Truncation error

38 Thank you !

39 Floating-point Notation
Decode a floating-point notation 1 8 bits Sign bit Exponent Mantissa Scientific notation : ± M x B E - 4 x x x 10.11

40 Practice 3 ( 5⅝)10= ( ? )2 0 1 0 1 . 1 0 1 ½ ¼ ⅛ 5 = 4+1 ⅝ = ½ + ⅛
( 5⅝)10= ( ? )2 Position's quantity 128 64 32 16 8 4 2 1 . 5 = 4+1 ⅝ = ½ + ⅛

41 Two’s complement notation
How to encode an integer in two’s complement notation? For positive integers, keep the binary representation. For negative integers, Start with N-bit representation of absolute value (positive integer) Complement each bit (change 0 to 1, and 1 to 0) Add one (Binary addition algorithm) E.g. Represent in Two’s complement The positive integer: 410 Complement each bit: Add one: -410

42 Answer ( )2= ( 1*2 + 1*1 + 0*0.5+1*0.25 )10 ( )2= ( 0*1 + 1* * * )10 ( 4.5 )10= ( )2 ( 5.625)10= ( )2 Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8 1/2 1/4 1/8

43 Patterns that Add Up to Zero
How to represent -1 ? Find a particular bit pattern results that represents zero when added to one. 0001 0000 1 -1 1 How to represent -3 ? Find a particular bit pattern results that represents zero when added to three. 0011 0000 3 -3 1

44 Floating-point Notation
Decode a floating-point notation 1 8 bits Sign bit Exponent Mantissa Scientific notation : ± M x B E - 4 * 2-1 * 21 * 22 x x x 10.11

45 Exercises 1 ( 5⅝)10= ( ? )2 5 = 4 +1 ⅝ = ½ + ⅛ 1 0 1 . 1 0 1 Position
( 5⅝)10= ( ? )2 5 = 4 +1 ⅝ = ½ + ⅛ Position 7 6 5 4 3 2 1 . -1 -2 -3 Position's quantity 27 26 25 24 23 22 21 20 2-1 2-2 2-3 128 64 32 16 8 1/2 1/4 1/8

46 ( )2= ( ? )10 23 1 16 8 4 2 1 16 4 2 1 = 23


Download ppt "Department of Computer Science Georgia State University"

Similar presentations


Ads by Google