5 + 3 ----- Try these, in decimal 5 + 3 ----- 8 Try these, - - PDF document

5 3
SMART_READER_LITE
LIVE PREVIEW

5 + 3 ----- Try these, in decimal 5 + 3 ----- 8 Try these, - - PDF document

Addition / Subtraction ICS3U Mr. Emmell Try these, in decimal 5 + 3 ----- Try these, in decimal 5 + 3 ----- 8 Try these, in decimal 8 + 4 ----- Try these, in decimal 8 + 4 ----- 1 2 How did you do that? When one column


slide-1
SLIDE 1

ICS3U

  • Mr. Emmell

Addition / Subtraction

Try these, in decimal

5 + 3

slide-2
SLIDE 2

Try these, in decimal

5 + 3

  • 8

Try these, in decimal

8 + 4

slide-3
SLIDE 3

Try these, in decimal

8 + 4

  • 1 2

When one column overflowed…. It incremented the next column

How did you do that?

slide-4
SLIDE 4

When one column… tried to have a higher value than our number system allowed!

How did you know it

  • verflowed?

Then you

  • Subtracted ten
  • Wrote the remainder
  • Added the carry

Try these, in octal

28 + 48

slide-5
SLIDE 5

Try these, in octal

28 + 48

  • 68

Try these, in octal

58 + 58

slide-6
SLIDE 6

Try these, in octal

58 + 58

  • 5 + 5 = 10!!!!

That’s too much This is base 8 so… 10 – 8 = 2

Try these, in octal

58 + 58

  • 1 28
slide-7
SLIDE 7

Try these, in octal

1 58 + 58

  • Try these, in octal

1 58 + 58

  • 2 28
slide-8
SLIDE 8

Try these, in octal

3 58 + 4 68

  • Try these, in octal

3 58 + 4 68

  • 1 0 38
slide-9
SLIDE 9

Hexadecimal works the same way!

316 + 616

  • Hexadecimal works the same way!

316 + 616

  • 916
slide-10
SLIDE 10

Hexadecimal works the same way!

716 + 616

  • Hexadecimal works the same way!

716 + 616

  • D16
slide-11
SLIDE 11

Hexadecimal works the same way!

B 916 + A16

  • Hexadecimal works the same way!

B 916 + A16

  • Remember!

In decimal, this is: 9 + 10 = 19

slide-12
SLIDE 12

Hexadecimal works the same way!

B 916 + A16

  • C 316

Hexadecimal works the same way!

2 616 + 7 E16

slide-13
SLIDE 13

Hexadecimal works the same way!

2 616 + 7 E16

  • A 416

Don’t forget binary too

1 0 0 12 + 1 0 1 12

slide-14
SLIDE 14

Don’t forget binary too

1 0 0 12 + 1 0 1 12

  • 1 0 1 0 02

Good news! We can’t… Not really. We need to learn about complements first

Now… how about subtraction?

slide-15
SLIDE 15

If it is 11:00 now, then three hours later it will be 2:00

11 + 3 = 14 ≡ 2 (mod 12) 2 o’clock

So instead, we add the complement.

Consider a 12 hour clock.

1 − 4 = −3 ≡ 9 (mod 12) 9 o’clock

So instead, we add the complement.

Similarly, if it is 1:00, then 4 hours ago it was 9 since

slide-16
SLIDE 16

Notice that subtracting 4 hours on the clock is the same as adding 8 hours (12 – 4). In particular, we could have computed it as follows:

1 − 4 ≡ 1 + 8 = 9 (mod 12)

So instead, we add the complement.

Use an 8-bit number as an example Those numbers range from 0-255 If we have 255 and add one, then we get zero because it ‘cycles back’.

Binary numbers work the same way

slide-17
SLIDE 17

How do we find the complement for a number in binary? We know that 200 – 50 is the same as 200 + (255-50) (Because we roll over after 255!)

So….?

⚫ Define how many bits you are using! 8-bit?

⚫ Always need to have leading zeroes.

⚫ Invert all the bits ⚫ Add one ⚫ BOOM – Two’s complement. Add normally

using binary addition.

HOW TO FIND “TWO’s COMPLEMENT”

slide-18
SLIDE 18

100 – 58 = 42 Now for this operation, we are really saying: 100 + (-58) = 42 Let’s convert to binary

Example

100 = 011001002

Remember! 8-bits What about -58?

Example

2 100 2 50 0 2 25 0 2 12 1 2 6 0 2 3 0 2 1 1 0 1

slide-19
SLIDE 19

58 = 001110102

Remember! 8-bits What about -58?

Example – Start with 58

2 58 2 29 0 2 14 1 2 7 0 2 3 1 2 1 1 0 1

001110102 //58 110001012

//FLIP

+1 //Add one 11000110

  • 58 = 110001102

Example

slide-20
SLIDE 20

0 1 1 0 0 1 0 02 1 1 0 0 0 1 1 02

Now we do the ‘addition’

0 1 1 0 0 1 0 02 1 1 0 0 0 1 1 02 1 0 0 1 0 1 0 1 02

If there is a leading one, we drop it (remember! 8-bits) Answer = 001010102

(42 !)

Now we do the ‘addition’

slide-21
SLIDE 21

Note: Rather than having our numbers go from 0 to 255 around a clock, we have them go from −128 to 127