DLD Lecture 03(Number conversion & arithmetic).pptx

alisyd730 10 views 30 slides Oct 07, 2024
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

Number conversion & arithmetic


Slide Content

Easy Approach: Numbering Systems And Arithmetic Operations On Hex, Binary, And Octal Lecture-03 Teacher: Dr. Syed Ali Asgher Email: [email protected]

2 12 Department of Computer Science

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

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

What is the two’s complement? A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value. 5

Example Suppose we're working with 8 bit and suppose we want to find how -28 would be expressed in two's complement notation. First we write out 28 in binary form. 0 0 0 1 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 0 1 1 Then we invert the digits. 0 becomes 1, 1 becomes 0. Then we add 1. That is how one would write -28 in 8 bit binary. 6

7 An 8-bit unsigned integer number can represent the values 0 to 255. However for signed number a two's complement 8-bit number can only represent non-negative integers from 0 to 127, because the rest of the bit represent the negative integers −1 to −128. 2 8 = 256

Common Powers (1 of 2) Base 10 8 Power Preface Symbol 10 -12 pico p 10 -9 nano n 10 -6 micro  10 -3 milli m 10 3 kilo k 10 6 mega M 10 9 giga G 10 12 tera T Value .000000000001 .000000001 .000001 .001 1000 1000000 1000000000 1000000000000

Common Powers (2 of 2) Base 2 9 Power Preface Symbol 2 10 kilo k 2 20 mega M 2 30 Giga G Value 1024 1048576 1073741824 What is the value of “k”, “M”, and “G”? In computing, particularly w.r.t. memory , the base-2 interpretation generally applies.

10

Example 11 / 2 30 = 1. Double click on My Computer 2. Right click on C: 3. Click on Properties

Review – multiplying powers For common bases, add powers 12 2 6  2 10 = 2 16 = 65,536 or… 2 6  2 10 = 64  2 10 = 64k a b  a c = a b+c

Arithmetic Operations on Hex, Binary, Octal 13

Binary Addition Rules: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 2 = 10 2 = 0 with 1 to carry 1 + 1 + 1 = 3 = 11 2 = 1 with 1 to carry 14

Binary Addition Two n -bit values Add individual bits Propagate carries E.g., 15 10101 21 + 11001 + 25 101110 46 1 1

Binary Addition 1 1 1 1 1 1 0 1 1 1 + 0 1 1 1 0 0 1 0 1 0 0 1 1 16 Verification 55 10 + 28 10 83 10 64 32 16 8 4 2 1 1 0 1 0 0 1 1 = 64 + 16 + 2 +1 = 83 10

Binary Addition Example Verification 1 0 0 1 1 1 + 0 1 0 1 1 0 + ___ 1 1 1 1 0 1 128 64 32 16 8 4 2 1 = = 17

Multiplication (1 of 3) Decimal (just for fun) 18 35 x 105 175 000 35 3675

Multiplication (2 of 3) Binary, two 1-bit values 19 A B A  B 1 1 1 1 1

Multiplication (3 of 3) Binary, two n -bit values As with decimal values E.g., 20 1110 x 1011 1110 1110 0000 1110 10011010

Fractions Decimal to decimal (just for fun) 21 3.14 => 4 x 10 -2 = 0.04 1 x 10 -1 = 0.1 3 x 10 = 3 3.14

Fractions Binary to decimal 22 10.1011 => 1 x 2 -4 = 0.0625 1 x 2 -3 = 0.125 0 x 2 -2 = 0.0 1 x 2 -1 = 0.5 0 x 2 = 0.0 1 x 2 1 = 2.0 2.6875

Fractions Decimal to binary 23 3.14579 .14579 x 2 0.29158 x 2 0.58316 x 2 1.16632 x 2 0.33264 x 2 0.66528 x 2 1.33056 etc. 11.001001...

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

Decimal Addition 111 3758 + 4657 8 4 1 5 25 What is going on? 1 1 1 (carry) 3 7 5 8 + 4 6 5 7 14 11 15 10 10 10 (subtract the base) 8 4 1 5

Octal Addition 0-7= 8 1 1 6 4 3 7 8 + 2 5 1 0 8 1 1 1 4 7 8 26 Example: 3 5 3 6 8 + 2 4 5 7 8 6 2 1 5

Hexadecimal Addition 1 1 Example: 7 C 3 9 16 + 3 7 F 2 16 B 4 2 B 16 27 8 A D 4 16 + 5 D 6 16 9 0 A A

Binary Subtraction 1 0 1 0 0 1 1 - 0 1 1 1 0 0 1 1 0 1 1 1 28 Verification 83 10 - 28 10 55 10 64 32 16 8 4 2 1 1 1 0 1 1 1 = 32 + 16 + + 4 + 2 +1 = 55 10

Exercise Hexadecimal: 650E + 08C1 = 4A6 + 1B3 = 4A6 – 1B3 = Octal: 162 + 537 = 456 + 123 = 456 – 173 = 29 Website: https://madformath.com/calculators/digital-systems/

Solutions HD 650E + 08C1 = 6DCF 4A6 + 1B3 = 659 4A6 – 1B3 = 2F3 OCTAL 162 + 537 = 721 456 + 123 = 601 456 – 173 = 263 30
Tags