Presentation is loading. Please wait.

Presentation is loading. Please wait.

Boolean Algebra, Bitwise Operations

Similar presentations


Presentation on theme: "Boolean Algebra, Bitwise Operations"β€” Presentation transcript:

1 Boolean Algebra, Bitwise Operations
Tutorial Two Boolean Algebra, Bitwise Operations CompSci Semester Two 2017

2 Boolean Values Two types: Generally given the familiar values 1 and 0
True False Generally given the familiar values 1 and 0 CompSci Semester Two 2017

3 Boolean Operators AND OR NOT 𝐴 𝑇 Symbol: βˆ™ Conjunction Symbol: +
T βˆ™ T = T, T βˆ™ F = F, 1 βˆ™ 1 = 1 OR Symbol: + Disjunction T + T = T, T + F = T, = 0 NOT Symbol: line over the operator Negation = F, = 1 𝐴 𝑇 CompSci Semester Two 2017

4 Truth Tables AND A B A βˆ™ B 1 CompSci Semester Two 2017

5 Truth Tables OR A B A + B 1 CompSci Semester Two 2017

6 Truth Tables NOT A 1 𝐴 CompSci Semester Two 2017

7 Bitwise Operations Work on bit patterns, individual bits
Manipulate values for comparisons/Calculations Bit Masking Very Fast (Directly supported by CPU) CompSci Semester Two 2017

8 Bitwise Operators XOR AND OR NOT Symbol: ^ Exclusive OR Symbol: &
CompSci Semester Two 2017

9 Bitwise operations XOR 1000 ^ 1011 = 0011 0111 ^ 1010 = 1101
CompSci Semester Two 2017

10 Bitwise operations AND 1000 & 1011 = 1000 0111 & 1000 = 0000
CompSci Semester Two 2017

11 Bitwise operations OR 1000 | 1011 = 1011 0111 | 1000 = 1111
CompSci Semester Two 2017

12 Bitwise operations NOT ~1010 = 0101 ~0111 = 1000
CompSci Semester Two 2017

13 ADDITION Take the two binary numbers 01 (1) and 10 (2) To add these two numbers, first align them vertically Then, as with adding two decimal numbers, start from the right, and go left Note: The above is not in two’s compliment. CompSci Semester Two 2017

14 Addition Cont. What happens if we have two 1’s in the same column? Like in decimal addition, you place the remainder of the addition in that column, and then the carry into the column one to its left (1)00 What’s with the brackets? CompSci Semester Two 2017

15 Subtraction Subtraction is a subset of addition, in that adding a numbers negative is the same as subtracting that number 10 – 5 = (-5) = 5 The same is true for binary arithmetic. This is something important to remember for later when working with the LC-3, as it doesn’t have a subtraction instruction. CompSci Semester Two 2017

16 Exercise 1 Calculate the result of the following 2’s Compliment arithmetic 1111 βˆ’0001 0000 βˆ’1010 CompSci Semester Two 2017

17 Solution 1 B β€œ ” left pad any numbers so both have the same number of bits 0111 = Now align them vertically, and add the 000111 (carry 1) (Carry 1) … (1) CompSci Semester Two 2017

18 Exercise 1 Solutions 10 + 1111 (-2 + -1) 0111 + 111001 (+7 + -7)
( ) ( ) 1111 βˆ’0001 (-1 – 1) 0000 βˆ’1010 (0 βˆ’βˆ’6) Now we’ll solve them all using the processes mentioned before (We won’t be aligning them for simplicities sake) CompSci Semester Two 2017

19 Exercise 1 Solutions 1110 + 1111 000111 + 111001 1111 βˆ’0001 0000 βˆ’1010
Step 1: Left pad any numbers that need to be CompSci Semester Two 2017

20 Exercise 1 Solutions 1110 + 1111 000111 + 111001 1111+1111 0000+ 0110
Step 2: Convert subtractions to additions CompSci Semester Two 2017

21 Exercise 1 Solutions 1110+1111 Carry: 0, Remainder: 1
Step 3: Add from right to left CompSci Semester Two 2017

22 Exercise 1 Solutions 1110+1111 Carry: 10, Remainder: 01
CompSci Semester Two 2017

23 Exercise 1 Solutions 1110+1111 Carry: 110, Remainder: 101
CompSci Semester Two 2017

24 Exercise 1 Solutions 1110+1111 Carry: 1110, Remainder: 1101
CompSci Semester Two 2017

25 Exercise 1 Solutions 1110+1111 Carry: 1110, Remainder: (1)1101
CompSci Semester Two 2017

26 Exercise 1 Solutions 1110+1111 Carry: 1110, Remainder: (1)1101
CompSci Semester Two 2017

27 Exercise 1 Solutions 1110+1111 Carry: 1110, Remainder: (1)1101
CompSci Semester Two 2017

28 Exercise 1 Solutions 1110+1111 = 1101 000111 + 111001 = 000000
= 1101 = = 1110 = 0110 Step 4: Truncate carry bits CompSci Semester Two 2017

29 Exercise 1 Solutions 1110+1111 = 1101 000111 + 111001 = 000000
= 1101 = 1111βˆ’0001 = 1110 0000βˆ’1010 = 0110 Step 5: Revert back to original equations CompSci Semester Two 2017

30 Exercise 1 Solutions βˆ’2+βˆ’1 = -3 +7+βˆ’7 = 0 βˆ’1βˆ’1 = -2 0βˆ’βˆ’6 = 6
βˆ’2+βˆ’1 = -3 +7+βˆ’7 = 0 βˆ’1βˆ’1 = -2 0βˆ’βˆ’6 = 6 Step 6: Convert to decimal to check answer CompSci Semester Two 2017

31 Carry and Overflow Carry Flag: overflow flag:
Set in the following: = (1)0000 (MSB carried out) 0000 – 0001 = (MSB carried in) overflow flag: = 1000 (4 + 4 = -8) = 0000 ( = 0) In unsigned arithmetic we care about the carry flag In signed arithmetic we care about the overflow flag CompSci Semester One 2017

32 Bit Shifting Left Shift (<<) Right Shift (>>)
Equivalent to multiplying the value by 2 𝑛 (+23) << 1 (n) = (+46) Right Shift (>>) Equivalent to dividing, and rounding down, the value by 2 𝑛 (-105) >> 1 (n) = (-53) This can change depending on if the value being shifted is signed or unsigned CompSci Semester Two 2017


Download ppt "Boolean Algebra, Bitwise Operations"

Similar presentations


Ads by Google