Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 18: Computational Thinking

Similar presentations


Presentation on theme: "Unit 18: Computational Thinking"— Presentation transcript:

1 Unit 18: Computational Thinking
Number systems

2 Addition The rules of binary addition are: 0 + 0 = 0 0 + 1 = 1
1 + 0 = 1 1 + 1 = 0 and carry 1 When there is a carry bit, then = 1 = 0 and carry 1 = 1 and carry 1

3 Example of Addition 0 1 1 0 1 + 1 0 1 1 1 ----------- = 1 0 0 1 0 0
= 1 + 1 = 0 and carry 1 = 0 and carry 1 = 1 and carry 1

4 Addition examples = = =

5 Negative numbers We can use the “sign and magnitude” method to indicate negative numbers We can split 8 bits into One bit (the leftmost, and sign bit) is 0 for a positive number and 1 for a negative number The remaining 7 bits give the value (or magnitude) So = + 127d, and = - 127d

6 Sign/magnitude examples
For example is -43d What is -83 in binary? What is in decimal?

7 Subtraction Implementing subtraction in a computer is easier if we can just use addition! The “two’s complement” method allows this. In this case a negative number is the “two’s complement” of its positive value

8 Two’s complement To write -28, we write out 28 in binary form 00011100
Then we invert the bits. 0 becomes 1, 1 becomes 0. Then we add 1. This represents -28

9 Two’s complement If the leftmost bit is 1, the number is negative
To reverse the process, start with Reverse the bits Add 1 Which is decimal 28

10 Two’s complement example
What is the binary for -30? What is in decimal?

11 Addition Adding -28 to 30 (=2) 11100100 (-28) 00011110 (30) 100000010
But we only have 8 bits, so we ignore the left most (carry) bit, and the answer is (2)

12 Subtraction 28 – 30 = -2 Take the two’s complement of 30
(flip the bits) (add 1) Add this to the binary for 28 (28) (-30) a negative number, which we can work out to be: (flip the bits) (add 1, to get decimal 2)

13 Subtraction example Subtract 69 decimal from 12 decimal using the “twos complement” method. Show the result in binary and decimal

14 Subtraction example result
= -57 d


Download ppt "Unit 18: Computational Thinking"

Similar presentations


Ads by Google