Download Presentation

Loading in 3 Seconds

Advertisement

X

This presentation is the property of its rightful owner.

- 650 Views
- Uploaded on
- Presentation posted in: Sports / GamesEducation / CareerFashion / BeautyGraphics / DesignNews / Politics

The Building Blocks: Binary Numbers, Boolean Logic and Gates

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 - - - - - - - - - - - - - - - - - - - - - - - - - -

The Building Blocks:Binary Numbers,Boolean Logicand Gates

Chapter 4

- Circuit: A path for electrons to flow through
(Negatively charged electrons are attracted to positively charged electrons)

- 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)

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

What is a CAPACITOR?

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.

- 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.

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

This is the computer’s main memory. It is a rows of memory chips.

RAM

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

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

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”.

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.

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.)

- 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 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.

Let’s look at 2542.

2x103 +5x102 + 4x101 +2x100

Now, let’s look at 1011.

1x23 +0x22 + 1x21 +1x20

- 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

- 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.

- 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.

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.

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

CONVERTING A NUMBER FROM

BASE 2 TO BASE 10

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

CONVERTING A NUMBER FROM

BASE 2 TO BASE 10

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

- 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

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

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

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

- 28
- WHICH IS?

- 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.)

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.

- 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)

- 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

- 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.

- 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

- 232
- WHICH IS?

- 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.

- 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.

- 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 (+)

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.

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’

011111111111111111111111111111111

First bit is used for the sign (+)

or

2(32-1) -1

11111111111111111111111111111111

or

- (2(32-1) -1)

Real numbers, also called floating point:

It can be any rational number

7.07 1/2

- 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.

- 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).

INT 7 vs. FLOAT 7.0

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

- CONVERT TO EXPONENTIAL NOTATION:
- FLOAT 7 = 0 1110000000000000 0 00000011

- 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.

111011.11

- .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.

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

CHARACTERS ARE CONVERTED TO

NUMBERS USING AN ENCODING

SCHEME

- 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.

SYMBOLASCIIEBCDIC

(space) 010000001000000

# 010001101111011

A 100000111000001

a110000110000001

3011001111110011

0 1 1 1 1 0 0 1

y

(Lowercase)

This byte represents one character — a lowercase y.

- 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.

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

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)

- -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

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)

BOTH ARE FOR REPRESENTING SIGNED NUMBERS

BOTH REPRESENT POSITIVE NUMBERS THE SAME WAY

THEY REPRESENT NEGATIVE NUMBERS DIFFERENTLY

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.

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’

- 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.)

- 011111111111111111111111111111111
- 2(32-1) -1

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

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

10000000000000000000000000000000

- 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. 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.

- 111011.11

- 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.

- 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

- 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.

- 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.

- 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.

- 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 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.

- 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!