3 – boolean logic and logic gates 4 – binary...

68
3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction to Computers and Computer Technology Rick Graziani Fall 2017

Upload: dangtuong

Post on 15-Mar-2018

234 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

3 – Boolean Logic and Logic Gates 4 – Binary Numbers

CS 1 Introduction to Computers and Computer Technology

Rick Graziani Fall 2017

Page 2: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 2

BIT – BInary digiT

•  Bit (Binary Digit) = Basic unit of information, representing one of two discrete states. The smallest unit of information within the computer.

•  The only thing a computer understands. •  Abbreviation: b •  Bit has one of two values:

–  0 (off) or 1 (on) –  0 (False) or 1 (True)

OFF ON

Page 3: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 3

Bits

•  Two patterns are known as the state of the bit.

•  For example, magnetic encoding of information on tapes, floppy disks, and hard disks are done with positive or negative polarity.

The boxes illustrate a position where magnetism may be set and sensed; pluses (red) indicate magnetism of positive polarity (1 bit), interpreted as “present” and minuses (blue) (0 bit).

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

Page 4: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 4

Bits

•  Bits are really only symbols. •  Used to display the one of two different, discrete states. •  Bits are used as:

–  Storing data •  Numbers •  Text characters •  Images •  Sound •  Etc.

–  Processing data

Page 5: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 5

Boolean Operations

•  Integrated Circuits (microchips) are used to store and manipulate (process) bits.

•  This is done using Boolean operations (in honor of mathematician George Boole, 1815-1864).

•  Boolean Operation: An operation that manipulates one or more true/false values

•  Specific operations –  AND –  OR –  XOR (exclusive or) –  NOT

•  Using Truth Tables we can uses different sets of logic operations to store, add, subtract, and more complicated operations with bit.

Page 6: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Boolean Algebra and logical expressions (Addendum)

•  Boolean algebra (due to George Boole) - The mathematics of digital logic –  Useful in dealing with binary system of numbers. –  Used in the analysis and synthesis of logical expressions.

•  Logical expressions – Expressions constructed using logical-variables and operators. –  Result is: True or False

•  Boolean algebra – In mathematics a variable uses one of the two possible values: 1 or 0

•  May also be represented as: –  Truth or Falsehood of a statement –  On or Off states of a switch –  High (5V) or low (0V) of a voltage level

Rick Graziani [email protected] 6

Page 7: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Used in electronics (Addendum)

•  Electrical circuits are designed to represent logical expressions –  Known as logic circuits.

•  Used to make important logical decisions in household appliances, computers, communication devices, traffic signals and microprocessors.

•  Three basic logic operations as listed below: –  OR operation –  AND operation –  NOT operation

Rick Graziani [email protected] 7

Page 8: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Logic gates

•  A logic gate is an electronic circuit/device which makes the logical decisions based on these operations.

•  Logic gates have: –  one or more inputs –  only one output

•  The output is active only for certain input combinations. •  Logic gates are the building blocks of any digital circuit.

Rick Graziani [email protected] 8

Page 9: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 9

Boolean Operations - AND

•  Truth tables (simple ones) •  AND operation

–  Both input values must be TRUE for output to be TRUE –  Kermit is a frog AND Miss Piggy is an actress –  Inputs to AND operation represent truth of falseness of the

compound statement.

AND = TRUE

TRUE TRUE

Page 10: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 10

Boolean Operations

•  Gate: –  A device that computes a Boolean operation –  A device that produces the output of a Boolean operation when

given the operation’s input values. •  Gates can be:

–  Gears –  Relays –  Optic devices –  Electronic circuits (microchips)

Page 11: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 11

Boolean Operations – AND Gate

0 = FALSE 1 = TRUE AND operation •  Both input values must

be TRUE for output to be TRUE

0

0 0

Truth Table

Inputs Output

0 0

0 1

1 0

1 1

0 0

1 0 0

1

0 0

0

1

1 1

1

Page 12: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 12

Off (False) On (True)

Off (False)

•  To build an AND gate: Two transistors connected together •  Two inputs (transistors A and B) and one output •  Transistor A: Off (False) •  Transistor B: On (True) •  Output: Off (False)

Page 13: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 13

On (True) On (True)

On (True)

•  Transistor A: On (True) •  Transistor B: On (True) •  Output: On (True)

Page 14: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 14

Boolean Operations - OR

•  Truth tables (simple ones) •  OR operation

–  Only one input values must be TRUE for output to be TRUE –  In Rick likes to surf OR Rick likes to go dancing. –  Taking both courses will also TRUE.

OR = TRUE TRUE True

Page 15: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 15

Boolean Operations – OR Gate

0 = FALSE 1 = TRUE OR operation •  At least one input value

must be TRUE for output to be TRUE

0

0 0

Truth Table

Inputs Output

0 0

0 1

1 0

1 1

0 0

1 1 1

1

0 1

1

1

1 1

1

Page 16: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 16

•  Two inputs (transistors A and B) and one output •  Transistor A: Off (False) •  Transistor B: Off (False) •  Output: Off (False)

Page 17: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 17

•  Two inputs (transistors A and B) and one output •  Transistor A: Off (False) •  Transistor B: On (True) •  Output: On (True)

Page 18: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 18

•  Two inputs (transistors A and B) and one output •  Transistor A: On (True) •  Transistor B: On (True) •  Output: On (True)

Page 19: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 19

Boolean Operations - XOR

•  Truth tables (simple ones) •  XOR operation

–  One and ONLY one input value can be TRUE for output to be TRUE

–  At noon Rick is going to surf the Hook XOR surf Liquor Stores (this is a surf spot)

–  Both cannot be true, as I cannot surf both spots at the same time.

XOR = TRUE TRUE False

Page 20: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 20

Boolean Operations – XOR Gate

0 = FALSE 1 = TRUE XOR operation •  Only one input value is

TRUE for output to be TRUE

Truth Table

Inputs Output

0 0

0 1

1 0

1 1

0

0 0

0 0

1 1 1

1

0 1

1

1

1 0

0

Page 21: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 21

Page 22: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 22

Page 23: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 23

Page 24: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 24

Boolean Operations – NOT Gate

0 = FALSE 1 = TRUE NOT operation •  Only one input •  Opposite of input NOT FALSE = TRUE NOT TRUE = FALSE

Truth Table

Inputs Output

0

1

0 1

1

1 0 0

Page 25: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 25

•  To build an NOT gate: One transistor •  One input and one output •  Transistor A: On (True) •  Current flows to ground wire and none

to output, so output is Off (False)

Current

Page 26: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 26

•  Transistor A: Off (False) •  Current flows to ground wire and

none to output, so output is Off (False)

Current

Page 27: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

http://www.neuroproductions.be/logic-lab/

Rick Graziani [email protected] 27

Page 28: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 28

Another way to write it…

0 = FALSE; 1 = TRUE

Page 29: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Binary Numbers

Page 30: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

•  Binary = Of two states

Rick Graziani [email protected] 30

Page 31: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 31

Binary Math

Page 32: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 32

Base 10 (Decimal) Number System

Digits (10): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Number of: 104 103 102 101 100

10,000’s 1,000’s 100’s 10’s 1’s 1 2 3 9 1 0 9 9 1 0 0

Page 33: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 33

Base 10 (Decimal) Number System

Digits (10): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Number of: 104 103 102 101 100

10,000’s 1,000’s 100’s 10’s 1’s 4 1 0 8 3 8 2 1 0 0 0 9 1 0 0 1 0

Page 34: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 34

Rick’s Number System Rules

•  All digits start with 0 •  A Base-n number system has n number of digits:

–  Decimal: Base-10 has 10 digits –  Binary: Base-2 has 2 digits –  Hexadecimal: Base-16 has 16 digits

•  The first column is always the number of 1’s •  Each of the following columns is n times the previous

column (n = Base-n) –  Base 10: 10,000 1,000 100 10 1 –  Base 2: 16 8 4 2 1 –  Base 16: 65,536 4,096 256 16 1

Page 35: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 35

Counting in Decimal (0,1,2,3,4,5,6,7,8,9)

1,000’s 100’s 10’s 1’s 0 1 2 3

... 9

1 0 1 1

... 1 8 1 9 2 0 2 1 2 2

1,000’s 100’s 10’s 1’s . . .

2 9 3 0 3 1

... 9 9

1 0 0 1 0 1

... 9 9 9

1 0 0 0

Page 36: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 36

Counting in Binary (0, 1)

8’s 4’s 2’s 1’s 0 1

1 0 1 1

1 0 0 1 0 1

8’s 4’s 2’s 1’s

1 1 0

1 1 1

1 0 0 0

1 0 0 1

1 0 1 0

1 0 1 1

1 1 0 0

1 1 0 1

1 1 1 0

1 1 1 1

Dec Dec 0 1 2 3 4 5 6

7

8

9

10

11

12

13

14

15

Page 37: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 37

Binary Math (more later)

0 0 1 10 11 100 101 +0 +1 +1 +1 +1 + 1 + 1 0 1 10 11 100 101 110 111 00000000 11111110 + 1 + 0 -> + 1 1000 …… 00000000 11111111

Page 38: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 38

Base 2 (Binary) Number System

Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20

128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 2 1 0 10 1 0 1 0 17 70 130 255

Page 39: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 39

Base 2 (Binary) Number System

Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20

128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 2 1 0 10 1 0 1 0 17 1 0 0 0 1 70 1 0 0 0 1 1 0 130 1 0 0 0 0 0 1 0 255 1 1 1 1 1 1 1 1

Page 40: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 40

Converting between Decimal and Binary

Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20

128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 1 0 0 0 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 172 192

Page 41: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 41

Converting between Decimal and Binary

Digits (2): 0, 1 Number of: 27 26 25 24 23 22 21 20

128’s 64’s 32’s 16’s 8’s 4’s 2’s 1’s Dec. 70 1 0 0 0 1 1 0 40 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 128 1 0 0 0 0 0 0 0 172 1 0 1 0 1 1 0 0 192 1 1 0 0 0 0 0 0

Page 42: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 42

Computers do Binary

0 1 •  Bits have two values: OFF and ON •  The Binary number system (Base-2) can represent OFF

and ON very well since it has two values, 0 and 1 –  0 = OFF –  1 = ON

•  Understanding Binary to Decimal conversion is critical in computer science, computer networking, digital media, etc.

Page 43: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 43

Rick’s Program

Page 44: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 44

Rick’s Program

Page 45: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 45

Rick’s Program

Page 46: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 46

Decimal Math - Addition

10,000’s 1,000’s 100’s 10’s 1’s

1 6 5 1 0 + 1 6 5 9 5

----------------------------- 50

1

13

1

3

1

Page 47: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 47

Binary Math - Addition

64’s 32’s 16’s 8’s 4’s 2’s 1’s

1 1 1 0 1 0 + 1 1 0 1 1

----------------------------- 10

1

10

1

1

1

0

1

1

Double check using Decimal.

Dec

58

27 + ----- 85

Page 48: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 48

Half Adder Gate – Adding two bits

Inputs: A, B S = Sum C = Carry

AND

XOR

A + B = 2’s 1’s

Page 49: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 49

Half Adder Gate – Adding two bits

Inputs: A, B S = Sum C = Carry

AND

XOR

A + B = 2’s 1’s 0 0 =

0 0

0 0

S C

0

0

0 + 0 ----

0

Page 50: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 50

Half Adder Gate – Adding two bits

Inputs: A, B S = Sum C = Carry

AND

XOR

A + B = 2’s 1’s 0 1 =

0 1

1 0

S C

1

0

0 + 1 ----

1

Page 51: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 51

Half Adder Gate – Adding two bits

Inputs: A, B S = Sum C = Carry

AND

XOR

A + B = 2’s 1’s 1 0 =

1 0

1 0

S C

1

0

1 + 0 ----

1

Page 52: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 52

Half Adder Gate – Adding two bits

Inputs: A, B S = Sum C = Carry

AND

XOR

A + B = 2’s 1’s 1 1 =

1 1

0 1

S C

0

1

1 + 1 ---- 1 0

Page 53: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 53

Marble Adding Machine

•  http://www.youtube.com/watch?v=GcDshWmhF4A&NR=1&feature=fvwp

Page 54: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 54

Page 55: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 55

Page 56: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 56

Page 57: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Text

Page 58: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 58

Digitizing Text

•  Earliest uses of PandA (Presence and Absence) was to digitize text (keyboard characters).

•  We will look at digitizing images and video later. •  Assigning Symbols in United States:

–  26 upper case letters –  26 lower case letters –  10 numerals –  20 punctuation characters –  10 typical arithmetic characters –  3 non-printable characters (enter, tab, backspace) –  95 symbols needed

Page 59: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 59

ASCII-7

•  In the early days, a 7 bit code was used, with 128 combinations of 0’s and 1’s, enough for a typical keyboard.

•  The standard was developed by ASCII (American Standard Code for Information Interchange)

•  Each group of 7 bits was mapped to a single keyboard character.

0 = 0000000 1 = 0000001 2 = 0000010 3 = 0000011 … 127 = 1111111

Page 60: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 60

Byte

Byte = A collection of bits (usually 7 or 8 bits) which represents a character, a number, or other information.

•  More common: 8 bits = 1 byte •  Abbreviation: B

Page 61: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 61

Bytes

1 byte (B) Kilobyte (KB) = 1,024 bytes (210) •  “one thousand bytes” 1,024 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 Megabyte (MB) = 1,048,576 bytes (220) •  “one million bytes” Gigabyte (GB) = 1,073,741,824 bytes (230) •  “one billion bytes”

Page 62: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Wikipedia

Rick Graziani [email protected] 62

Page 63: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 63

ASCII-8

•  IBM later extended the standard, using 8 bits per byte.

•  This was known as Extended ASCII or ASCII-8

•  This gave 256 unique combinations of 0’s and 1’s.

0 = 00000000 1 = 00000001 2 = 00000010 3 = 00000011 … 255 = 11111111

1

Page 64: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 64

ASCII-8

Page 65: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 65

Try it!

•  Write out Cabrillo College (Upper and Lower case) in bits (binary) using the chart above.

0100 0011 0110 0001 … C a

1

Page 66: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 66

The answer!

0100 0011 0110 0001 0110 0010 0111 0010 0110 1001 0110 1100 C a b r i l 0110 1100 0110 1111 0010 0000 0100 0011 0110 1111 0110 1100 l o space C o l 0110 1100 0110 0101 0110 0111 0110 0101 l e g e

1

Page 67: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

Rick Graziani [email protected] 67

•  Although ASCII works fine for English, many other languages need more than 256 characters, including numbers and punctuation.

•  Unicode uses a 16 bit representation, with 65,536 possible symbols. •  Unicode can handle all languages. •  www.unicode.org

Unicode

Page 68: 3 – Boolean Logic and Logic Gates 4 – Binary Numbersrgraziani/cs1/cs1-3-BooleanLogic-4-BinaryNumber… · 3 – Boolean Logic and Logic Gates 4 – Binary Numbers CS 1 Introduction

3 – Boolean Logic and Logic Gates 4 – Binary Numbers

CS 1 Introduction to Computers and Computer Technology

Rick Graziani