21
Foundation of Computer Science Junior Programmer Camp #8

JPC#8 Foundation of Computer Science

Embed Size (px)

Citation preview

Page 1: JPC#8 Foundation of Computer Science

Foundation of Computer Science

Junior Programmer Camp #8

Page 2: JPC#8 Foundation of Computer Science

Chapter 1: Number Systems & Radix Number

Page 3: JPC#8 Foundation of Computer Science

Radix Numbers

• Base 2 (Binary)- 0, 1

• Base 8 (Octal)- 0, 1, 2, 3, 4, 5, 6, 7

• Base 10 (Decimal)- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

• Base 16 (Hexadecimal)– 0, 1, 2, 3 , …, 8, 9, A, B, C, D, E, F

Page 4: JPC#8 Foundation of Computer Science

Base Conversion

Base X to Base 10 (Decimal)– Starting from the last digit, multiply

that digit by X0

– Increase the power of X by 1 and repeat until you have done all digits

– Sum up the results

Page 5: JPC#8 Foundation of Computer Science

Base Conversion (cont.)

Example:Convert 110112, 5467, 878 to base 10

Result : 2727971

Page 6: JPC#8 Foundation of Computer Science

Base Conversion (cont.)

Base 10 (Decimal) to any base X– Divide the number by X.– Write down the remainder.– Repeat the previous two steps until

the result is 0.– The actual result is the digit sequence

of the remainders from the last to first.

Page 7: JPC#8 Foundation of Computer Science

Base Conversion (cont.)

Example:Convert 34510 to base 2,3,16

Result: 1010110012

11021203

15916

Page 8: JPC#8 Foundation of Computer Science

Base Conversion (cont.)

Base 2 (Binary) to Base 8 (Octal)– Group 3 digits from the right side– Convert each group to its octal

representationDo you think that number in base 2 can

also be converted to Base 16 (Hexadecimal) directly somehow?

Page 9: JPC#8 Foundation of Computer Science

Binary Arithmetic

• Addition:0 + 0 = 0 1 + 0 = 1 0 + 1 = 1 1 + 1 =

10

• Subtraction:0 – 0 = 0 1 – 0 = 1 0 – 1 = 1 1 - 1 =

0

• Multiplication:0 x 0 = 0 1 x 0 = 0 0 x 1 = 0 1 x 1 =

1

Page 10: JPC#8 Foundation of Computer Science

Binary Arithmetic (Try it!)

Example:

101001101 + 1111101011001001011 - 1101110111101 x 11001

Page 11: JPC#8 Foundation of Computer Science

Chapter 2: Logic Gates & Circuits

Page 12: JPC#8 Foundation of Computer Science

Gates and Circuits Simulator

http://logic.ly/demo/

Page 13: JPC#8 Foundation of Computer Science

NOT Gate

Boolean expression : A’Truth table: Input Output

0 1

1 0

Page 14: JPC#8 Foundation of Computer Science

AND & NAND Gate

Boolean expression : A ∙ B [AND](A ∙ B)’

[NAND]Truth table:

Input OutputA B AND NAND

0 0 0 1

0 1 0 1

1 0 0 1

1 1 1 0

Page 15: JPC#8 Foundation of Computer Science

OR & NOR Gate

Boolean expression : A + B [OR](A + B)’ [NOR]

Truth table: Input OutputA B OR NOR

0 0 0 1

0 1 1 0

1 0 1 0

1 1 1 0

Page 16: JPC#8 Foundation of Computer Science

XOR & XNOR Gate

Boolean expression : A B [XOR](A B)’ [XNOR]

Truth table: Input Output

A B XOR XNOR

0 0 0 1

0 1 1 0

1 0 1 0

1 1 0 1

Page 17: JPC#8 Foundation of Computer Science

Circuits

A circuit is a combination of gates.

Page 18: JPC#8 Foundation of Computer Science

Boolean expression

Boolean expression is D = (A + B)’ NOT (A OR B)E = B ∙ C B AND CQ = D + E D OR E

= (A + B)’+(B ∙ C) (NOT (A OR B)) OR (B AND C)

Page 19: JPC#8 Foundation of Computer Science

Truth tableInput Output

A B C D (A + B)’

E (B ∙ C )

Q((A + B)’+(B ∙ C) )

0 0 0 1 0 1

0 0 1 1 0 1

0 1 0 0 0 0

0 1 1 0 1 1

1 0 0 0 0 0

1 0 1 0 0 0

1 1 0 0 0 0

1 1 1 0 1 1

Page 20: JPC#8 Foundation of Computer Science

Give it a try!

Find the Boolean expression and the truth table of this circuit.

Page 21: JPC#8 Foundation of Computer Science

Give it a try!

Draw a circuit this Boolean expression:X = ((A B) + (C’∙ D))’

E