Loading in 2 Seconds...

The Building Blocks: Binary Numbers, Boolean Logic and Gates

Loading in 2 Seconds...

- By
**Ava** - Follow User

- 738 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'The Building Blocks: Binary Numbers, Boolean Logic and Gates' - Ava

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Basic Concepts of Electricity

- Circuit: A path for electrons to flow through

(Negatively charged electrons are attracted to positively charged electrons)

Basic Concepts of Electricity

- Current:Flow of electrons through a conducting material measured in (amps)
- Voltage: (Electrical pressure) The force which causes current to flow through an electrical conductor. (measured in volts)

Basic Concepts of Electricity

- Resistance: (electrical friction): A property of materials that impedes current and causes the power loss in the form of heat dissipation. (measured in Ohm)

Capacitor: (Reservoir)An electronic device that stores electricity. A simple capacitor consists of two conductors, separated by an insulating material called a dielectric.

In the old days the Capacitor was called a condenser, but we don't use that name anymore. So what is a capacitor ?

A capacitor is a special electrical component that you can use to charge it with electrons, or energy in the circuit. Once you

charge the capacitor to it's maximum, it stays charged until you discharge it. It was called a capacitor, because this device

possesses capacitance. Capacitance is the inherent property of electric circuit that opposes change in voltage. Property of circuit

whereby energy may be stored in electrostatic fields and use to do something with later on or immediately.

Basic Concepts of Electricity

- Transistor :A semiconductor,made of silicon and gallium arsenide, is a device that amplifies a signal or opens and closes a circuit.
- In computers, it acts as a switch.
- DiodeAn electronic device that controls the flow of electrons. A diode lets current flow in only one direction.
- Transistors and other devices -- such as resistors, capacitors and diodes -- make up logic gates. Logic gates make up circuits, and circuits make up electronic systems, such as computers. See for more info. Transistor (router)

Logic Gates:Transistors and other devices -- such as resistors, capacitors and diodes -- make up logic gates.

Logic gates make up circuits

Circuits make up electronic systems, such as computers.

The Electronic Representation of Data

How does data and instructions get “stored” inside the computer?

A look inside a memory chip:

Each chip contains millions of capacitors lined up in nice, neat rows.

Each capacitor has a transistor (switch) attached to it.

A capacitor can be charged or discharged

When it’s charged, it represent the numeric value ‘1’.

When it’s discharged, no current flow into a capacitor, it remains discharged.

The discharged state represent the numeric value ‘0’.

So a capacitor can be used to store a single digit - 0 or 1. That is why a single capacitor is called a bit - it stores a binary digit.

A SINGLE BIT- it’s a capacitor attached to a transistor.

This is a single bit. It can be charged (representing the value ‘1’) or discharged (representing the value ‘0’)

Power source

Transistor

current

Capacitor

Recall that the transistor acts as a switch. If it is “closed” it is acting as an insulator. It stops the flow of the current into the capacitor. If it is “open” it is acting as a conductor. It lets the current flow into the capacitor - allowing it to be charged or “on”.

Two stable electronic states are possible:

On and off

fully charged/fully discharged

charged positively/charged negatively

magnetized/nonmagnetized

magnetized clockwise/magnetized ccw

So, two digits can be represented electronically - 0 and 1.

All types of data is stored in these devices

numeric values (base 10 numbers must be converted to base 2 numbers) (0000110 = 6, 0000111=7, etc.)

character values (we used encoding schemes to convert letters of the alphabet to base-2 numeric values) (0100010=‘A’, 0100011=‘B’, etc.)

images, sound, and full-motion video must also be converted into base-2 numeric values using encodingschemes. (0011=“white”, 1010=“green”, etc.)

FIRST, HOW DO WE HUMANS REPRESENT TEXT & NUMERIC DATA?

- FOR NUMBERS, WE USE 10 DIFFERENT SYMBOLS (0,1,2,3,4,5,6,7,8,9). WE CALL THIS METHOD THE BASE 10 NUMBERING SYSTEM.
- FOR LETTERS, WE USE 26 DIFFERENT SYMBOLS (A, B, C….).
- FURTHER, WE USE “SIGN MAGNITUDE NOTATION” (A + OR - SIGN FOLLOWED BY A VALUE) TO DISTINQUISH BETWEEN POSITIVE AND NEGATIVE NUMBERS.
- FOR FRACTIONS, WE USE DECIMAL POINTS TO SEPARATE THE WHOLE NUMBER PART FROM THE FRACTION.

How does a computer stores numeric values?

How are numbers like 3,543 and -54 and 2.3454 and 1/5 represented in the computer’s memory?

Base 10 numbers have to be converted to base 2 numbers in order to be stored internally by the computer.

Comparing decimal and binary system

Let’s look at 2542.

2x103 +5x102 + 4x101 +2x100

Now, let’s look at 1011.

1x23 +0x22 + 1x21 +1x20

THE COMPUTER REPRESENTS ALL DATA ELECTRONICALLY

- A CAPACITOR-LIKE DEVICE CAN BE ELECTRONICALLY CHARGED OR DISCHARGED.
- IF IT IS CHARGED, IT IS SAID TO BE IN AN “ON” STATE. THIS ON-STATE REPRESENTS THE NUMERIC VALUE “1”.
- IF IT IS DISCHARGED, IT IS SAID TO BE IN AN “OFF” STATE. THIS OFF-STATE REPRESENTS THE NUMERIC VALUE “0”
- SO 1 DEVICE CAN BE USED TO REPRESENT ONE OF TWO POSSIBLE DIGITS.
- SEE HANDOUT #1

2 ELECTRONIC STATES CAN ONLY REPRESENT 2 NUMBERS - BUT THERE ARE 10 UNIQUE NUMBERS

- HOW CAN IT WORK?
- BASE 10 NUMBERS HAVE TO BE CONVERTED TO BASE 2 NUMBERS IN ORDER TO BE STORED INTERNALLY BY THE COMPUTER.
- BASE 2 NUMBERS USE ONLY 1’S AND 0’S AS DIGITS.
- BASE 2 NUMBERS CAN BE REPRESENTED IF WE USE SEVERAL OF THESE ELECTRONIC DEVICES

Base 2 numbering system - a notation for representing values where only two unique symbols are used.

SO, TO REPRESENT A NUMBER OR LETTER IN A COMPUTER….

- LET’S SAY THAT WE CHOOSE TO USE 8 ELECTRONIC DEVICES TO STORE ONE SINGLE NUMBER
- FIRST, THE NUMBER MUST BE CONVERTED TO AN 8-DIGIT, BASE-2 NUMBER
- THEN, THE BASE 2 NUMBER CAN BE REPRESENTED BY A SERIES OF 8 ELECTRONIC DEVICES.

THE NUMBER x WOULD BE REPRESENTED AS y:

x y____

0 00000000 (ALL 8 DEVICES DISCHARGED)

1 00000001 (1ST 7 DEVICES DISCHARGED, 8TH IS CHARGED)

2 00000010 ETC.

3 00000011

4 00000100

5 00000101

6 00000110

7 00000111

A bit is a single storage unit. It can store a 0 or a 1.

But computers are designed to use bits in sets of 8.

(Typical values are 16, 32, 64)

A set of 8 bits is called a byte.

A byte is the smallest unit of storage in a computer.

Therefore, all numeric values in a computer must contain at least 8 digits.

Leading zeros will be used to hold the extra digits when necessary.

Bytes vs. bitsTHE NUMBER x IS REPRESENTED AS y:

x y____

0 00000000 (ALL 8 capacitors DISCHARGED)

1 00000001 (1ST 7 capacitors DISCHARGED, 8TH IS CHARGED)

2 00000010 ETC.

3 00000011

4 00000100

5 00000101

6 00000110

7 00000111

BASE 2 TO BASE 10

TAKE 00000111:1 * 20 (1) = 1

1 * 21 (2) = 2

1 * 22 (4) = 4

0 * 23 (8) = 0

0 * 24 (16) = 0

0 * 25 (32) = 0

0 * 26 (64) = 0

0 * 27 (128) = 0

7

BASE 2 TO BASE 10

TAKE 11000111:1 * 20 (1) = 1

1 * 21 (2) = 2

1 * 22 (4) = 4

0 * 23 (8) = 0

0 * 24 (16) = 0

0 * 25 (32) = 0

1 * 26 (64) = 64

1 * 27 (128) = 128

199

CONVERTING FROM BASE 10 TO BASE 2

- Take a number and subtract the highest 2? That you can without resulting in a negative number.
- Keep subtractingthe highest 2? Until you get to 0.
- Take 45.
- Subtract 25 (32)
- Get 13
- Subtract 23 (8)
- Get 5
- Subtract 22 (4)
- Get 1
- Subtract 20 (1)
- Get 0
- Answer: 00101101
- (A “1” in the 5th, 3th, 2nd and 0th positions.)

0 0 1 0 1 1 0 1

Converting fractional numbers to base 2

Let’s look at the following example

- In decimal system: .75= 7x10-1 + 5x10-2
- Representing .11=1x2-1+1x2-2

=1/2+ 1/4

Converting fractional numbers to base 2

Let’s try to convert .8 to binary number.

- We can write .8=1/2+1/4 + 1/32+ 1/64+1/512
- Converting to binary:
- .110011001

What’s the largest value that 8 bit devices can represent?

- THE VALUE: 11111111
- 28 - 1
- WHICH IS?

SO HOW CAN THE COMPUTER STORE THE NUMBER 1 MILLION?

- 1,000,000 is a 7-digit number in base 10 but it is a 20-digit number in base 2. It cannot be represented using only 8 bits!
- We’ll need 20 bits instead of 8 to represent 1 million.
- And we’ll need 24 bits to represent the number 10 million (a 24-digit number in base 2.)

DATA STRUCTURES

If a program needs to use numbers (or other types of data) that are too large to fit into a single byte:

- Programmers can can instruct the computer to (temporarily) create larger storage bins by grouping more than 8 bit devices together to create a single unit of storage.
- A designated storage bin consisting of more than one byte is called a data structure.

Setting up data structures

- As a programmer, you can write a declaration statement like this:
- Integer x
- Character y
- Float c
- Then, the computer will set aside the bytes you need to hold that type of data (integer, character, or float)

PROGRAMMING MODELS

- Different computer languages allow you to designate different sizes and types of data structures.
- In “c” language, you can create (declare) data structures that hold:
- integers
- long integers
- characters
- character strings
- real numbers
- large real numbers and so on

DECLARING STRUCTURES TO HOLD UNSIGNED INTEGERS:

- In c, you can declare a structure to hold an unsigned integer like this:

unsigned integer count

- When this statement is executed in a program, the computer will set up a “storage bin” of size 4 bytes (on a Unix-based system)
- Any value that is put in that storage bin will be interpreted as apositive integer.

WHAT’S THE LARGEST VALUE THAT THIS 4-BYTE STRUCTURE CAN HOLD?

- 11111111111111111111111111111111
- 232 - 1
- Which is?
- This is the largest value that can be represented in this data structure.
- What’s the smallest value it can hold? 0

PROGRAMMING MODELS

- Different computer languages allow you to designate different sizes and types of data structures.
- In c++, you can create data structures called objects that can hold “images”, “sound clips”, “video”, etc.

DECLARING STRUCTURES TO HOLD SIGNED INTEGERS:

- In C++, you can declare a structure to hold a signed integer (includes a + or -) like this:

signed integer counter

- When this statement is executed in a program, the computer will set up a “storage bin” of size 4 bytes.
- Any value that is put in that storage bin will be interpreted as a signed integer.

Representing Negative Numbers

- Binary digits can be used to represent not only numbers but other forms of data as well, including + and - signs.
- We can have a ‘1’ represent a negative sign (-)
- and a ‘0’ represent a positive sign (+)

SUMMARIZING THE DIFFERENCE BETWEEN SIGNED NUMBERS AND UNSIGNED NUMBERS

In C++, you can declare:

- “signed integer” data structure
- or an “unsigned integer” data structure

The same binary code could represent different numbers depending on what type of structure it is stored in.

TAKE THE BINARY CODE: 1110001

As a signedinteger, 1110001 would be the value -49

As an unsignedinteger, 1110001 would be the value 113

As a character, 1110001 would be the “lower case ‘q’

WHAT IS THE LARGEST VALUE THAT CAN BE REPRESENTED IN A SIGNED INTEGER CELL?

011111111111111111111111111111111

First bit is used for the sign (+)

or

2(32-1) -1

WHAT IS THE SMALLEST VALUE THAT CAN BE REPRESENTED IN A SIGNED INTEGER CELL?

11111111111111111111111111111111

or

- (2(32-1) -1)

DECLARING STRUCTURES TO HOLD REAL NUMBERS:

Real numbers, also called floating point:

It can be any rational number

7.0 7 1/2

DECLARING STRUCTURES TO HOLD REAL NUMBERS:

- A SIGNED FLOAT LIKE THIS:

FLOAT SALES

- WHEN THIS STATEMENT IS EXECUTED IN A PROGRAM, THE COMPUTER WILL SET UP A
- STORAGE BIN OF SIZE 4 BYTES (32 BITS)
- BUT 7.0 IN A FLOAT CELL IS REPRESENTED DIFFERENTLY THAN 7 IN AN INTEGER CELL.

FLOAT STRUCTURES

- BREAK A NUMBER INTO FOUR PARTS:
- A SIGN OF THE MANTISSA
- A MANTISSA
- A SIGN OF THE EXPONENT
- AN EXPONENT
- 7.0 MUST BE CONVERTED TO EXPONENTIAL NOTATION (BUT USING THE POWER OF 2).

EXAMPLE:

INT 7 vs. FLOAT 7.0

- INT 7 = 00000000000000000000000000000111
- FLOAT 7:
- CONVERT TO EXPONENTIAL NOTATION:
- .111 Exp 3 OR .111 Exp 00000011
- FLOAT 7 = 0 1110000000000000 0 00000011

1. ENCODE THE FRACTION PART (.75):

- 1. Convert the fractional part to base 2:

Since:

.5 = .1

.25 = .01

.125 = .001

.0625 = .0001

etc.

Therefore:

.75 = .11

.375 = .011

.875 = .111

etc.

2. ENCODE THE FULL NUMBER: (59.75):

111011.11

3. CONVERT TO EXPONENTIAL NOTATION:

- .11101111 * exp 6
- OR
- .11101111 * exp 110 (6 in binary)

The number of places the decimal point would have to move to the right to represent the correct value.

5. HERE IS WHAT -59.75 LOOKS LIKE STORED AS A (single precision) FLOAT:

1 111011110000000 0 00000110

Here is the sign of the mantissa (1 means negative)

Here is the exponent

Here is the mantissa.

Here is the sign of the exponent

Encoding schemes, ASCII, EBCDIC, and unicode

- Three encoding schemes:
- ASCII uses 7 bits to a represent character
- EBCDIC (developed by IBM)
- Unicode is a newly-developed encoding scheme
- that used 16 digits to represent letters instead of 8
- It includes English as well as symbols as well such as Chinese, Japanese, Arabic and Hebrew letters.

(space) 0100000 01000000

# 0100011 01111011

A 1000001 11000001

a 1100001 10000001

3 0110011 11110011

DECLARING STRUCTURES TO HOLD CHARACTERS:

- IN C, YOU CAN DECLARE A STRUCTURE TO HOLD A CHARACTER:

CHARACTER ANSWER

- WHEN THIS STATEMENT IS EXECUTED IN A PROGRAM, THE COMPUTER WILL SET UP A “STORAGE BIN” OF SIZE 1 BYTE.
- ANY VALUE THAT IS PUT IN THAT STORAGE BIN WILL BE INTERPRETED AS A CHARACTER.

-6 USING TWO’S COMPLEMENT NOTATION:

TAKE 6: 0 0 0 0 0 1 1 0

TAKE COMPLEMENT OF 6: 1 1 1 1 1 0 0 1

ADD 1 TO THE COMPLEMENT + 1

GET -6 1 1 1 1 1 0 1 0

WHAT ABOUT THE NUMBER 0?

TAKE THE NUMBER: 0 0 0 0 0 0 0 0

TAKE COMPLEMENT: 1 1 1 1 1 1 1 1

ADD 1 TO THE COMPLEMENT + 1

GET 1| 0 0 0 0 0 0 0 0 (SAME#)

(“EXCESS” DIGIT IS TRUNCATED OR LOST)

WHAT ABOUT -1, -2, -3, -4, & -5?

- -1 = 1 1 1 1 1 1 1 1
- -2 = 1 1 1 1 1 1 1 0
- -3 = 1 1 1 1 1 1 0 1
- -4 = 1 1 1 1 1 1 0 0
- -5 = 1 1 1 1 1 0 1 1
- -6 = 1 1 1 1 1 0 1 0

CONVERSIONS THE OTHER WAY:

TAKE 11111010. YOU KNOW THE NUMBER IS NEGATIVE BECAUSE OF THE 1 IN THE LEFT-MOST BIT.

WRITE THE NUMBER: 11111010

FIND COMPLEMENT OF IT: 00000101

ADD 1 TO THE COMPLEMENT: + 1

GET THE POSITIVE VALUE 00000110

(IT’S 6, SO THE TOP NUMBER MUST BE -6)

SUMMARIZING THE DIFFERENCE BETWEEN SIGN MAGNITUDE NOTATION AND TWO’S COMPLEMENT NOTATION:

BOTH ARE FOR REPRESENTING SIGNED NUMBERS

BOTH REPRESENT POSITIVE NUMBERS THE SAME WAY

THEY REPRESENT NEGATIVE NUMBERS DIFFERENTLY

SUMMARIZING THE DIFFERENCE BETWEEN SIGNED NUMBERS AND UNSIGNED NUMBERS

IN C, YOU CAN DECLARE A “SIGNED INTEGER” DATA STRUCTURE OR AN “UNSIGNED INTEGER” DATA STRUCTURE

THE SAME BINARY CODE COULD REPRESENT DIFFERENT NUMBERS DEPENDING ON WHAT TYPE OF STRUCTURE IT IS STORED IN.

TAKE THE BINARY CODE: 1110001

AS A SIGNED INTEGER (USING SIGN MAGNITUDE NOTATION), 1110001 WOULD BE THE VALUE -49

AS A SIGNED INTER (USING TWO’S COMPLEMENT NOTATION, 1110001 WOULD BE THE VALUE -15.

AS AN UNSIGNED INTEGER, 1110001 WOULD BE THE VALUE 113

AS A CHARACTER, 1110001 WOULD BE THE “LOWER CASE ‘q’

WHY TWO’S COMPLEMENT?

- TWO’S COMPLEMENT NOTATION MAKES IT POSSIBLE FOR THE COMPUTER TO SUBTRACT BY ADDING THE NEGATIVE (SIMPLYING THE INTERNAL CIRCUITRY):
- SAY YOU WANT TO FIND 12 - 6
- 12 = 00001100
- + -6 = 11111010
- = 6 = 1|00000110
- ( THE LEFT-MOST DIGIT IS TRUNCATED DUE TO OVERFLOW.)

WHAT IS THE LARGEST VALUE THAT CAN BE REPRESENTED IN A SIGNED INTEGER CELL?

- 011111111111111111111111111111111
- 2(32-1) -1

WHAT IS THE SMALLEST VALUE THAT CAN BE REPRESENTED IN A SIGNED INTEGER CELL?

- 1000000000000000000000000000001
- - (2(32-1) -1)

HOW MANY DIFFERENT VALUES CAN BE REPRESENTED IN A SIGNED INTEGER CELL?

- THEORETICALLY, IT SHOULD BE: 232
- BUT ACTUALLY, IT’S 232 - 1 (BECAUSE BOTH THESE NUMBERS ARE 0:)

00000000000000000000000000000000

10000000000000000000000000000000

DECLARING STRUCTURES TO HOLD REAL NUMBERS:

- IN C, YOU CAN DECLARE A STRUCTURE TO HOLD A SIGNED FLOAT LIKE THIS:

FLOAT SALES

- WHEN THIS STATEMENT IS EXECUTED IN A PROGRAM, THE COMPUTER WILL SET UP A STORAGE BIN OF SIZE 4 BYTES (32 BITS)
- BUT THE INTERPRETATION OF THE BITS IN THAT CELL IS DIFFERENT THAN FOR INTEGER CELLS
- IN A FLOAT CELL, “7” WOULD BE STORED AS:
- +1.11 * 22

A floating point value is also called a real number. It can be any rational number.

1. ENCODE THE FRACTION PART (.75):

- 1. Convert the fractional part to base 2:

Since:

.5 = .1

.25 = .01

.125 = .001

.0625 = .0001

etc.

Therefore:

.75 = .11

.375 = .011

.875 = .111

etc.

2. ENCODE THE FULL NUMBER: (59.75):

- 111011.11

3. CONVERT TO EXPONENTIAL NOTATION:

- 1.1101111 * exp 5
- OR
- 1.1101111 exp 101 (5 in binary)
- NOW, DROP THE LEADING ‘1” BECAUSE IT IS “IMPLIED” AND YOU HAVE A “MANTISSA” OF 1101111.

The number of places the decimal point would have to move to the right to represent the correct value.

4. EXPRESS THE EXPONENT AS AN “OFFSET” FROM 127:

- 127 = 1 1 1 1 1 1 1
- + 5 = 0 0 0 0 1 0 1
- 132 = 1 0 0 0 0 1 0 0

5. HERE IS WHAT -59.75 LOOKS LIKE STORED AS A (single precision) FLOAT:

- 1 10000100 11011110000000000000000

1 means the mantissa is negative

Here is the value of 59.75 with the leading 1 dropped (because it’s implied)

Here is the exponent (5) expressed as an offset from 127.

SO FAR, WE’VE TALKED ABOUT NUMBERS. HOW DOES THE COMPUTER REPRESENT THE CHARACTERS OF THE ALPHABET?

- CHARACTERS ARE CONVERTED TO NUMBERS USING AN ENCODING SCHEME
- THE MOST COMMONLY-USED ENCODING SCHEME IS: ASCII
- ASCII = AMERICAN STANDARD CODE FOR INFORMATION INTERCHANGE

ASCII - A commonly-used encoding scheme for converting letters to base-2 numbers so that they can be stored electronically by a computer.

You may have heard of EBCDIC or unicode

- Two alternative encoding schemes are EBCDIC (developed by IBM) and unicode. Unicode is a newly-developed encoding scheme that used 16 digits to represent letters instead of 8 - It has more than just A to Z in its “character set” - it includes foreign symbols as well such as chinese, japanese, arabic and hebrew letters.

DECLARING STRUCTURES TO HOLD CHARACTERS:

- IN C, YOU CAN DECLARE A STRUCTURE TO HOLD A CHARACTER:
- CHARACTER ANSWER
- WHEN THIS STATEMENT IS EXECUTED IN A PROGRAM, THE COMPUTER WILL SET UP A “STORAGE BIN” OF SIZE 1 BYTE.
- ANY VALUE THAT IS PUT IN THAT STORAGE BIN WILL BE INTERPRETED AS A CHARACTER.

THE “ADDTWO” PROGRAM:

- THE PROGRAM DECLARED THE VARIABLES “NUMONE”, “NUMTWO” AND “SUM” AS SIGNED INTEGERS.
- THE NUMBER 10 BILLION WAS RECEIVED FOR THE VALUE IN “NUMONE”, (A 33-DIGIT NUMBER IN BASE 2), AND THE “SIGNED INTEGER” STRUCTURE, OF SIZE 4 BYTES (OR 32 BITS) COULD NOT REPRESENT IT CORRECTLY. THE LEFT-MOST BIT(S) WERE TRUCATED RESULTING IN A WRONG ANSWER TO THE SUM CALCULATION.

WHAT TO DO?

- IF POSSIBLE, DECLARE DATA STRUCTURES THAT WILL BE SUFFICIENT IN SIZE TO HOLD YOUR DATA. (IN C, YOU CAN DECLARE A “LONG INTEGER” WHICH IS OF SIZE 8 BYTES.)
- RECOGNIZE THE COMPUTER’S LIMITATIONS!

Download Presentation

Connecting to Server..