Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.