Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAT10403 CHAPTER 4 COMPUTER ARITHMETIC By Noordiana Kassim

Similar presentations


Presentation on theme: "DAT10403 CHAPTER 4 COMPUTER ARITHMETIC By Noordiana Kassim"— Presentation transcript:

1 DAT10403 CHAPTER 4 COMPUTER ARITHMETIC By Noordiana Kassim

2 NUMBER SYSTEMS

3 NUMBER SYSTEMS A number system defines how a number can be represented using distinct symbols. A number can be represented differently in different systems. For example, the two numbers (2A)16 and (52)8 both refer to the same quantity, (42)10, but their representations are different.

4 HOW COMPUTER STORES INFORMATION???

5 Binary Numbers are at the heart of how a computer stores all information
Computers Store ALL information using Binary Numbers Computers use binary numbers in different ways to store different types of information. Common types of information that are stored by computers are : Whole numbers (i.e. Integers). Examples: etc Numbers with decimal points. Examples: etc Textual information (including letters, symbols and digits) Keep reading …

6 All information on computers is stored as numbers
All information that is processed by computers is converted in one way or another into a sequence of numbers. This includes numeric information textual information and Pictures Therefore, if we can derive a way to store and retrieve numbers electronically this method can be used by computers to store and retrieve any type of information.

7 CASE STUDY EXAMPLE Bitmap images are widely used on digital cameras, smartphones and online. Common bitmap image file types include JPEG, GIF and PNG. Bitmaps are also known as pixel maps or raster graphics.

8 CASE STUDY EXAMPLE (cont…)
Bitmap images are organized as a grid of colored squares called pixels (short for 'picture elements'). When zooming in or enlarging a bitmap image, the pixels are stretched and made into larger blocks. This is why bitmap images appear as poor quality when enlarged too much.

9 CASE STUDY EXAMPLE (cont…)
Each color of an image is stored as a binary number. In the black-and-white image below, each pixel is either black or white. You need a binary value for each different color. As each pixel is either black or white, this image can be encoded with a value of 0 for white and 1 for black.

10 Common Number Systems System Base Symbols Used by humans?
Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Octal 8 0, 1, … 7 Hexa- decimal 16 0, 1, … 9, A, B, … F

11 What is a binary number? A binary number is a number that includes only ones and zeroes. The number could be of any length The following are all examples of binary numbers Another name for binary is base-2 (pronounced "base two")

12 What is a decimal number?
The numbers that we are used to seeing are called decimal numbers. decimal numbers consist of the digits from 0 (zero) through 9. The following are examples of decimal numbers 3 76 Another name for decimal numbers are base-10 (pronounced "base ten") numbers.

13 Quantities/Counting (1 of 3)
Decimal Binary Octal Hexa- decimal 1 2 10 3 11 4 100 5 101 6 110 7 111

14 Quantities/Counting (2 of 3)
Decimal Binary Octal Hexa- decimal 8 1000 10 9 1001 11 1010 12 A 1011 13 B 1100 14 C 1101 15 D 1110 16 E 1111 17 F

15 Quantities/Counting (3 of 3)
Decimal Binary Octal Hexa- decimal 16 10000 20 10 17 10001 21 11 18 10010 22 12 19 10011 23 13 10100 24 14 10101 25 15 10110 26 10111 27 Etc.

16 Conversion Among Bases
The possibilities: Decimal Octal Binary Hexadecimal

17 Quick Example 2510 = = 318 = 1916 Base

18 Weight 12510 => 5 x 100 = x 101 = x 102 = Base

19 Binary to Decimal Decimal Octal Binary Hexadecimal

20 Binary to Decimal Technique
Multiply each bit by 2n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results

21 BINARY TO DECIMAL Example
Bit “0” => 1 x 20 = x 21 = x 22 = x 23 = x 24 = x 25 = 32 4310

22 Hexadecimal to Decimal
Octal Binary Hexadecimal

23 Hexadecimal to Decimal
Technique Multiply each bit by 16n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results

24 HEXADECIMAL TO DECIMAL Example
ABC16 => C x 160 = 12 x 1 = B x 161 = 11 x 16 = A x 162 = 10 x 256 = 2560 274810

25 Decimal to Binary Decimal Octal Binary Hexadecimal

26 Decimal to Binary Technique Divide by two, keep track of the remainder
First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 Etc.

27 DECIMAL TO BINARY Example
12510 = ?2 12510 =

28 Hexadecimal to Binary Decimal Octal Binary Hexadecimal

29 Hexadecimal to Binary Technique
Convert each hexadecimal digit to a 4-bit equivalent binary representation

30 HEXADECIMAL TO BINARY Example
10AF16 = ?2 A F 10AF16 =

31 Decimal to Hexadecimal
Octal Binary Hexadecimal

32 Decimal to Hexadecimal
Technique Divide by 16 Keep track of the remainder

33 DECIMAL TO HEXADECIMAL Example
= ?16 = 4D216 77 2 16 = D 0 4

34 Binary to Hexadecimal Decimal Octal Binary Hexadecimal

35 Binary to Hexadecimal Technique Group bits in fours, starting on right
Convert to hexadecimal digits

36 BINARY TO HEXADECIMAL Example
= ?16 B B = 2BB16

37 Exercise – Convert ... Decimal Binary Octal Hexa- decimal 33 1110101
703 1AF Don’t use a calculator! Skip answer Answer

38 Exercise – Convert … Decimal Binary Octal Hexa- decimal 33 100001 41
Answer Decimal Binary Octal Hexa- decimal 33 100001 41 21 117 165 75 451 703 1C3 431 657 1AF

39 Common Powers (1 of 2) Base 10 Power Preface Symbol pico p nano n
10-12 pico p 10-9 nano n 10-6 micro 10-3 milli m 103 kilo k 106 mega M 109 giga G 1012 tera T Value .001 1000

40 Common Powers (2 of 2) Base 2 What is the value of “k”, “M”, and “G”?
Preface Symbol 210 kilo k 220 mega M 230 Giga G Value 1024 What is the value of “k”, “M”, and “G”? In computing, particularly w.r.t. memory, the base-2 interpretation generally applies

41 Example In the lab… 1. Double click on My Computer 2. Right click on C: 3. Click on Properties / 230 =

42 Fractions Decimal to decimal (just for fun)
3.14 => 4 x 10-2 = x 10-1 = x 100 =

43 Fractions Binary to decimal
=> x 2-4 = x 2-3 = x 2-2 = x 2-1 = x 20 = x 21 =

44 Fractions = (exactly)

45 Fractions = (approximately)

46 Fractions Decimal to binary
x x x x x x etc.

47 Exercise – Convert ... Decimal Binary Octal Hexa- decimal 29.8
3.07 C.82 Don’t use a calculator! Skip answer Answer

48 Exercise – Convert … Decimal Binary Octal Hexa- decimal 29.8
Answer Decimal Binary Octal Hexa- decimal 29.8 35.63… 1D.CC… 5.8125 5.64 5.D 3.07 3.1C 14.404 C.82

49 ARITHMETIC LOGIC UNIT (ALU)

50 ARITHMETIC & LOGIC UNIT
Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point (real) numbers May be separate FPU (Floating-Point Unit : maths co-processor) May be on chip separate FPU (486DX +)

51 ALU INPUTS AND OUTPUTS Operand Result

52 INTEGER REPRESENTATION

53 Number representation
Representing whole numbers Representing fractional numbers

54 Integer Representations
Signed magnitude notion Two’s complement notation.

55 Representation of negative numbers
Is a representation of negative numbers possible? Unfortunately: you can not just stick a negative sign in front of a binary number. (it does not work like that) There are three methods used to represent negative numbers. Signed magnitude notation Excess notation notation Two’s complement notation

56 Signed Magnitude Representation
Unsigned: - and + are the same. In signed magnitude the left-most bit represents the sign of the integer. 0 for positive numbers. 1 for negative numbers. The remaining bits represent to magnitude of the numbers.

57 Example - Suppose 10011101 is a signed magnitude representation.
The sign bit is 1, then the number represented is negative The magnitude is with a value = 29 Then the number represented by is –29. position 7 6 5 4 3 2 1 Bit pattern contribution - 24 23 22 20

58 Exercise 1 3710 has in signed magnitude notation. Find the signed magnitude of –3710 ? Using the signed magnitude notation find the 8-bit binary representation of the decimal value 2410 and Find the signed magnitude of –63 using 8-bit binary sequence?

59 Disadvantage of Signed Magnitude
Addition and subtractions are difficult. Signs and magnitude, both have to carry out the required operation. They are two representations of 0 = = To test if a number is 0 or not, the CPU will need to see whether it is or 0 is always performed in programs. Therefore, having two representations of 0 is inconvenient.

60 Signed-Summary In signed magnitude notation, Advantages:
The most significant bit is used to represent the sign. 1 represents negative numbers 0 represents positive numbers. The unsigned value of the remaining bits represent The magnitude. Advantages: Represents positive and negative numbers Disadvantages: two representations of zero, Arithmetic operations are difficult.

61 Two’s Complement Notation
The most used representation for integers. All positive numbers begin with 0. All negative numbers begin with 1. One representation of zero i.e. 0 is represented as 0000 using 4-bit binary sequence.

62 Two’s Complement Notation
In twos complement notation, the negation of an integer can be formed with the following rules: Take the Boolean complement of each bit of the integer (including the sign bit). That is, set each 1 to 0 and each 0 to 1. Treating the result as an unsigned binary integer, add 1. These two-step process is referred to as the twos complement operation.

63 Two’s Complement Notation
+18 = (twos complement) bitwise complement = ___________ = -18

64 Alternative Representation for 4-Bit Integers
Decimal Representation Sign-Magnitude Representation Twos Complement Representation +7 0111 +6 0110 +5 0101 +4 0100 +3 0011 +2 0010 +1 0001 +0 0000 -1 1001 1111 -2 1010 1110 -3 1011 1101 -4 1100 -5 -6 -7

65 DIGITAL LOGIC

66 BOOLEAN ALGEBRA Mathematical foundation of digital logic.
In this case, it makes use of logical variables and operations. Variable may take the value :- 1 (TRUE) 0 (FALSE) Basic logical operations are :- AND ( .  dot symbol) OR ( +  plus symbol) NOT ( ¯  overbar or ‘  apostrophe symbol)

67 BOOLEAN ALGEBRA Examples : A AND B = A · B A OR B = A + B NOT A = Ā
Other useful operators : XOR (exclusive OR) two logical operands is 1, if and only if exactly one of the operands has the value 1. NAND (not AND) NOR (not OR)

68 BOOLEAN ALGEBRA Boolean Operators of Two (2) Input Variables 1 P Q
NOT P (P) P AND Q (P · Q) P OR Q (P + Q) P NAND Q P NOR Q (P+Q) P XOR Q (P O Q) 1 +

69 GATES Gate is an electronic circuit that produces an output signal that is a simple Boolean operation on its input signal. A device that performs a basic operation on electrical signals Fundamental building block of all digital logic circuit. Logical functions are implemented by the interconnection of gates. Typically, logic diagrams are black and white, and the gates are distinguished only by their shape

70 GATES Basic gates used in digital logic are : AND OR NOT NAND NOR XOR
Each gate is defined in three (3) ways: Graphical symbol or logic diagram Algebraic notation/function or Boolean Expression Truth table A table showing all possible input value and the associated output values)

71 BASIC LOGIC GATES

72 BINARY SYSTEM Computers are made of a series of switches
Each switch has two states: ON or OFF Each state can be represented by a number – 1 for “ON” and 0 for “OFF”

73 Switching Circuits AND OR

74 NOT Gate A NOT gate accepts one input value and produces one output value

75 NOT Gate By definition, if the input value for a NOT gate is 0, the output value is 1, and if the input value is 1, the output is 0 A NOT gate is sometimes referred to as an inverter because it inverts the input value

76 AND Gate An AND gate accepts two input signals
If the two input values for an AND gate are both 1, the output is 1; otherwise, the output is 0

77 OR Gate If the two input values are both 0, the output value is 0; otherwise, the output is 1

78 XOR Gate XOR, or exclusive OR, gate
An XOR gate produces 0 if its two inputs are the same, and a 1 otherwise Note the difference between the XOR gate and the OR gate; they differ only in one input situation When both input signals are 1, the OR gate produces a 1 and the XOR produces a 0

79 XOR Gate

80 NAND and NOR Gates The NAND and NOR gates are essentially the opposite of the AND and OR gates, respectively 4–15

81 Review of Gate Processing
A NOT gate inverts its single input value An AND gate produces 1 if both input values are 1 An OR gate produces 1 if one or the other or both input values are 1

82 Review of Gate Processing
An XOR gate produces 1 if one or the other (but not both) input values are 1 A NAND gate produces the opposite results of an AND gate A NOR gate produces the opposite results of an OR gate

83 Converting between circuits and equations
Find the boolean expression/output of the following circuit Answer: (x+y) y x+y (x+y)y y __

84 Converting between circuits and equations
Find the output/algebraic function of the following circuit Answer: x x y x y y ___ _ _

85 EXERCISE Find the value (output) at point Q for the following logic gates circuit if A = 0 and B = 1

86 EXERCISE Find the value (output) at point Q for the following logic gates circuit if A = 0 and B = 1

87 EXERCISE Construct/Produce a truth table based on the following logic gates circuit

88 ANSWER

89 EXERCISE Construct/Produce a truth table based on the following logic gates circuit

90 ANSWER

91 EXERCISE

92

93

94

95

96


Download ppt "DAT10403 CHAPTER 4 COMPUTER ARITHMETIC By Noordiana Kassim"

Similar presentations


Ads by Google