Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Systems

Similar presentations


Presentation on theme: "Introduction to Computer Systems"โ€” Presentation transcript:

1 Introduction to Computer Systems
Department of Computer Science and Information Systems Lecturer: Steve Maybank Spring 2020 Week 3a: Boolean Operations 28 January 2020 Birkbeck College, U. London

2 Recall: Binary Numbers
In the standard notation for binary numbers a bit string such as 1001 stands for a sum of powers of 2: 1x23+0x22+0x21+1x20 Binary[1001] and Decimal[9] are different names for the same number Birkbeck College, U. London

3 Recall: Conversion of Decimal to Binary
Let m be a strictly positive integer Problem: find b such that Binary[b] = Decimal[m] Solution: m = 2q+r # r is the rightmost bit in b Binary[c] = Decimal[q] # easier because q < m b = c||r Birkbeck College, U. London

4 Recall: Binary Addition
column: 1 1 ===== There is a carry from column 1 to column 2 and from column 2 to column 3 In tests or examinations, always show the carries Brookshear, Section 1.5

5 Recall: Twoโ€™s Complement
If ๐‘ฅ,๐‘ฆ, ๐‘ฅ+๐‘ฆ are in the correct range, then the twoโ€™s complement representations of ๐‘ฅ and ๐‘ฆ can be added as if they were standard binary numbers to obtain the tc representation of ๐‘ฅ+๐‘ฆ. TC ๐‘ฅ = rightmost n bits of ๐‘ฅ+ 2 ๐‘› TC ๐‘ฅ+๐‘ฆ =rightmost_n ๐‘ฅ+๐‘ฆ+ 2 ๐‘› =rightmost_n ๐‘ฅ+ 2 ๐‘› +๐‘ฆ+ 2 ๐‘› =rightmost_n(TC(๐‘ฅ)+TC(y)) Brookshear, Section 1.6

6 Worksheet for Week 2 Convert binary 1011 to decimal. Convert decimal
1011 to binary. Convert hexadecimal 12F and 194 to binary Attempt the decimal sums 5+1, 12+5, 5-11 using 5 bit twoโ€™s complement. If ๐‘  is a bit string such that reverse ๐‘  =complement ๐‘  then show that the length of ๐‘  is even Birkbeck College

7 Birkbeck College, U. London
George Boole 1815 (Lincoln)-1864 (Ballintemple) 1849: publishes โ€œAn investigation into the laws of thought, on which are founded the mathematical theories of logic and probabilitiesโ€ Birkbeck College, U. London

8 Birkbeck College, U. London
Comparison of Numbers ย Symbol ย Description ย True Falseย  ย > greater thanย  ย 5 > 1 5 > 10ย  ย >= greater than or equal to 6 >= 6ย  ย 1 >= 7 ย < less thanย  ย 5 < 6 ย 5 < 5 ย <= less than or equal to ย 2 <= 2 ย 3 <= 2 ย == equal to 4 == 4ย  ย 4 == 5 True and False are referred to as truth values Birkbeck College, U. London

9 Examples of Boolean Statements
5 > 4 NOT(4 == 2) (5 > 4) AND (6 > 2) (1 > 4) OR (2 > 6) Note the use of NOT, AND and OR to create complicated statements out of simpler ones Brookshear, Section 1.1

10 Birkbeck College, U. London
Application A Boolean statement is either True (1) or False (0) Boolean statements are used to control the order in which the instructions in a program are carried out Example: x = 4 if(x > 6) then code_A else code_B Birkbeck College, U. London

11 Unary and Binary Boolean Operations
A unary Boolean operation takes a truth value as input and outputs a truth value. Example: NOT A binary Boolean operation takes two truth values as input, and outputs a truth value. Examples: AND, OR, XOR Brookshear, Section 1.1

12 Boolean Operations: AND, OR
These are truth tables. 1 = True, 0 = False. A B C 1 A B C 1 C = A AND B C = A OR B Brookshire, Section 1.1

13 Boolean Operations: XOR, NOT
1 = True, 0 = False A B C 1 A C 1 C = NOT A C=A XOR B Brookshire, Section 1.1

14 Birkbeck College, U. London
Boolean Statements Today is Thursday OR Today is Friday NOT[It is morning] He is in London AND There is life on Mars Each statement has a truth value. If the truth values of statements of A, B are known, then the truth values of (A OR B), NOT(A) and (A AND B) can be calculated. Birkbeck College, U. London

15 Combinations of Boolean Operations
NOT(A AND B) A OR NOT(B) (A OR B) OR C A OR (B OR C) NOT(NOT(A) AND NOT(B)) Birkbeck College, U. London

16 Application of a Boolean Operation
k = 0 n = 27 If 2k+1 > n, Print(k); halt k = k+1 go to 3 Variables in this program: k, n Birkbeck College, U. London

17 Birkbeck College, U. London
While Loop Version k = 0 n = 27 while (2k+1 <= n) k = k+1 endWhile print k halt Birkbeck College, U. London

18 Boolean Operations for Addition
Each digit z 1 , ๐‘ง 2 , ๐‘ง 3 can be obtained using a ternary Boolean operation, ๐‘ง 1 = ๐‘œ๐‘ 1 ๐‘ฅ 1 , ๐‘ฅ 2 , ๐‘ฆ 1 ๐‘ง 2 = ๐‘œ๐‘ 2 ๐‘ฅ 1 , ๐‘ฅ 2 , ๐‘ฆ 1 ๐‘ง 3 = ๐‘œ๐‘ 3 ๐‘ฅ 1 , ๐‘ฅ 2 , ๐‘ฆ 1 x2 x1 y1 ====== z3 z2 z1 Birkbeck College, U. London

19 Birkbeck College, U. London
Binary Addition x2 x1 y1 ====== z3 z2 z1 Birkbeck College, U. London

20 How Many Binary Boolean Operations?
Answer 16. Why? A truth table with columns A, B, C has one row for each pair of values of A, B. This gives four rows. Each Boolean operation is defined by the entries in column C. The number of different choices for column C is 2x2x2x2 = 16. Birkbeck College, U. London

21 Birkbeck College, U. London
Example Use truth tables to show that A OR (B AND C) = (A OR B) AND (A OR C) Birkbeck College, U. London


Download ppt "Introduction to Computer Systems"

Similar presentations


Ads by Google