HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.
-
Upload
pierce-holmes -
Category
Documents
-
view
220 -
download
0
Transcript of HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.
![Page 1: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/1.jpg)
HOW COMPUTERS HOW COMPUTERS MANIPULATE DATAMANIPULATE DATA
Chapter 1
Coming up: Analog vs. Digital
![Page 2: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/2.jpg)
1-2
Hardware and SoftwareHardware and SoftwareHardware
◦the physical, tangible parts of a computer keyboard,
monitor, disks, wires, chips, etc.
Software◦programs and data
a program is a series of instructions
A computer requires both hardware and software; otherwise useless without the other
![Page 3: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/3.jpg)
Digital InformationDigital InformationComputers store all information digitally:
◦ numbers◦ text◦ graphics and images◦ video◦ audio◦ program instructions
In some way, all information is digitized - broken down into pieces and represented as numbers
Coming up: Representing Text Digitally
![Page 4: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/4.jpg)
Representing Text DigitallyRepresenting Text DigitallyFor example, every character is stored as a
number, including spaces, digits, and punctuation
Corresponding upper and lower case letters are separate characters
H i , H e a t h e r .
72 105 44 32 72 101 97 116 104 101 114 46
Coming up: Binary Numbers
![Page 5: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/5.jpg)
Binary NumbersBinary NumbersOnce information is digitized, it is represented and
stored in memory using the binary number system
A single binary digit (0 or 1) is called a bit
Devices that store and move information are cheaper and more reliable if they have to represent only two states
A single bit can represent two possible states, like a light bulb that is either on (1) or off (0)
Permutations of bits are used to store values
Coming up: Bit Permutations
![Page 6: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/6.jpg)
Bit PermutationsBit Permutations1 bit
01
2 bits
00011011
3 bits
000001010011100101110111
4 bits
00000001001000110100010101100111
10001001101010111100110111101111
Each additional bit doubles the number of possible permutations
Coming up: Bit Permutations
![Page 7: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/7.jpg)
Bit PermutationsBit PermutationsEach permutation can represent a particular
itemThere are 2N permutations of N bitsTherefore, N bits are needed to represent 2N
unique items21 = 2 items
22 = 4 items
23 = 8 items
24 = 16 items
25 = 32 items
1 bit ?
2 bits ?
3 bits ?
4 bits ?
5 bits ?
How manyitems can be
represented by
Coming up: Java and Unicode
![Page 8: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/8.jpg)
Java and UnicodeJava and UnicodeHow do we map from numbers to characters?
In Java we use the Unicode specification
which maps each character to a 16-bit number.
So, how many possible characters can we have? 216 = 65536
ASCII is an older set that was 8-bits and thus could represent only 28=256
Note: The creators of Unicode started with ASCII, so the 256 ASCII character codes are a subset of Unicode
Coming up: Java and Unicode
![Page 9: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/9.jpg)
Java and UnicodeJava and UnicodeSee:
http://www.alanwood.net/demos/ansi.html
Unicode also includes some non-printable characters like null, tab, line feed, delete,…
Why 65,000 characters? We only have 26 letters!
Coming up: Binary – How does the computer see numbers?
![Page 10: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/10.jpg)
Binary – How does the computer Binary – How does the computer see numbers?see numbers?
Computers represent information digitally, but only using a series of 1s and 0s.
Binary = Base 2
Decimal = Base 10
Hexadecimal = Base 16
Coming up: Decimal Numbers (normal)
![Page 11: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/11.jpg)
Decimal Numbers Decimal Numbers (normal)(normal)In decimal (base 10) we
represent a number between 0-9 with one digit. To get any higher we use another position
23
Coming up: Binary Conversions
![Page 12: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/12.jpg)
Binary ConversionsBinary Conversions
5037 = 103*5 + 102*0 + 101*3 + 100*7
Now, what about Binary, which is Base 2?
Available digits then are 1 and 0 only.
Binary 101 is what in decimal?
Coming up: Binary Conversions
![Page 13: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/13.jpg)
JokeJokeThere are only 10 kinds of people
in this world. Those who know binary and those who don’t.
Coming up: Hexadecimal – base 16
![Page 14: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/14.jpg)
Hexadecimal – base 16Hexadecimal – base 16Base sixteen means we need 16 digits.. 0-9
is 10 digits, how do I get more? A,B,C,D,E,F are valid “digits” in Hex. A=10, B=11, C=12, D=13, E=14, F=15
So, a hex number looks like:◦ 3A or FFF or A2C4B
What is 1A in decimal?◦ 161*1 + 160*10 = 26 decimal
Normally hexadecimal numbers are preceded by “0x” which means it is a hex number.
Coming up: What is 0x20 in decimal?
![Page 15: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/15.jpg)
How to convert from decimal to How to convert from decimal to binarybinaryGiven a number (24) find the
largest place value that is lower than the number
26 = 6425 = 3224 = 1623 = 822 = 421 = 220 = 1
Coming up: Convert 9 into binary
Next divide the number by the place value to determine the digit for that position
24/16 = 1 Repeat process with remainder
(8 in this example)8/8 = 1So I need a 1 in the 16 position
and 8 position:= 11000
![Page 16: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/16.jpg)
Convert 9 into binaryConvert 9 into binary
26 = 6425 = 3224 = 1623 = 822 = 421 = 220 = 1
Coming up: Convert 7 into binary?
8 is the largest placevalue that fits inside 9, so
9/8 = 1Remainder is 11 is the largest place value that
fits in 1, so1/1 = 1Remainder is 0
1001 = 9
![Page 17: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/17.jpg)
Convert 35 to Convert 35 to hexadecimalhexadecimal
163=4096162=256161=16160=1
Coming up: Conclusions
16 is the largest placevalue that fits inside 35, so
35/16 = 2Remainder is 33/1 = 3Remainder is 0
0x23 = 35
![Page 18: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/18.jpg)
ConclusionsConclusions
You should understand the math to do conversions to/from binary/decimal/hexadecimal
We’ll use this later in a project and lab. You may even see a question on it on the exam
End of presentation
![Page 19: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/19.jpg)
1-19
JavaJavaA programming language specifies
the words and symbols that we can use to write a program
A programming language employs a set of rules that dictate how the words and symbols can be put together to form valid program statements
It was introduced in 1995 and it's popularity has grown quickly since
![Page 20: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/20.jpg)
1-20
Java Program StructureJava Program StructureIn the Java programming language:
◦A program is made up of one or more classes
◦A class contains one or more methods◦A method contains program
statements
A Java application always contains a method called main
See HelloWorld.java
![Page 21: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/21.jpg)
1-21
Java Program StructureJava Program Structure
public class HelloWorld
{
}
// comments about the class
class header
class body
Comments can be placed almost anywhere
![Page 22: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/22.jpg)
1-22
Java Program StructureJava Program Structure
public class HelloWorld
{
}
// comments about the class
public static void main (String[] args)
{
}
// comments about the method
method headermethod body
![Page 23: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/23.jpg)
1-23
IdentifiersIdentifiersAn identifier can be made up of letters, digits,
the underscore character ( _ ), and the dollar sign
Identifiers cannot begin with a digit
Java is case sensitive - Total, total, and TOTAL are different identifiers
By convention, programmers use different case styles for different types of identifiers, such as
◦ title case for class names - Lincoln
◦ upper case for constants - MAXIMUM
![Page 24: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/24.jpg)
1-24
Program DevelopmentProgram DevelopmentThe mechanics of developing a program
include several activities◦ writing the program in a specific
programming language (such as Java)◦ translating the program into a form that
the computer can execute investigating and fixing various types of errors that can occur
Software tools can be used to help with all parts of this process
![Page 25: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/25.jpg)
1-25
Language LevelsLanguage LevelsThere are four programming
language levels:◦machine language (CPU specific)◦assembly language◦high-level language◦fourth-generation language
The other levels were created to make it easier for a human being to read and write programs
![Page 26: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/26.jpg)
1-26
Programming LanguagesProgramming LanguagesEach type of CPU executes only a
particular machine languageA program must be translated into
machine language before it can be executed
A compiler is a software tool which translates source code into a specific target language
Often, that target language is the machine language for a particular CPU type
The Java approach is somewhat different
![Page 27: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/27.jpg)
1-27
Java TranslationJava TranslationThe Java compiler translates Java source
code into a special representation called bytecode
Java bytecode is not the machine language for any traditional CPU
Another software tool, called an interpreter, translates bytecode into machine language and executes it
Therefore the Java compiler is not tied to any particular machine
Java is considered to be architecture-neutral
![Page 28: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/28.jpg)
1-28
Syntax and SemanticsSyntax and SemanticsThe syntax rules of a language
define how we can put together symbols, reserved words, and identifiers to make a valid program
The semantics of a program statement define what that statement means (its purpose or role in a program)
A program that is syntactically correct is not necessarily logically (semantically) correct
A program will always do what we tell it to do, not what we meant to tell it to do
![Page 29: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/29.jpg)
1-29
ErrorsErrorsA program can have three types of errorsThe compiler will find syntax errors and
other basic problems (compile-time errors)◦ If compile-time errors exist, an executable
version of the program is not createdA problem can occur during program
execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors)
A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)
![Page 30: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/30.jpg)
1-30
Basic Program Basic Program DevelopmentDevelopment
errors
errors
Edit andsave program
Compile program
Execute program andevaluate results
![Page 31: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/31.jpg)
1-31
Problem SolvingProblem SolvingThe purpose of writing a program is to solve a
problem
Solving a problem consists of multiple activities:
◦ Understand the problem
◦ Design a solution
◦ Consider alternatives and
refine the solution
◦ Implement the solution
◦ Test the solution
These activities are not purely linear – they overlap and interact
![Page 32: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/32.jpg)
1-32
Problem SolvingProblem SolvingThe key to designing a solution is
breaking it down into manageable pieces
When writing software, we design separate pieces that are responsible for certain parts of the solution
An object-oriented approach lends itself to this kind of solution decomposition
We will dissect our solutions into pieces called objects and classes
![Page 33: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/33.jpg)
1-33
Object-Oriented Object-Oriented ProgrammingProgrammingJava is an object-oriented programming
languageAs the term implies, an object is a
fundamental entity in a Java programObjects can be used effectively to
represent real-world entitiesFor instance, an object might represent a
particular employee in a companyEach employee object handles the
processing and data management related to that employee
![Page 34: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/34.jpg)
1-34
ObjectsObjectsAn object has:
◦ state - descriptive characteristics
◦ behaviors - what it can do (or what can be done to it)
The state of a bank account includes its current balance
The behaviors associated with a bank account include the ability to make deposits and withdrawals
Note that the behavior of an object might change its state
![Page 35: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/35.jpg)
1-35
ClassesClassesAn object is defined by a class
A class is the blueprint of an object
The class uses methods to define the behaviors of the object
The class that contains the main method of a Java program represents the entire program
A class represents a concept, and an object represents the embodiment of that concept
Multiple objects can be created from the same class
![Page 36: HOW COMPUTERS MANIPULATE DATA Chapter 1 Coming up: Analog vs. Digital.](https://reader030.fdocuments.in/reader030/viewer/2022033103/56649e185503460f94b04d85/html5/thumbnails/36.jpg)
1-36
Objects and ClassesObjects and Classes
Bank Account
A class(the concept)
John’s Bank AccountBalance: $5,257
An object(the realization)
Bill’s Bank AccountBalance: $1,245,069
Mary’s Bank AccountBalance: $16,833
Multiple objectsfrom the same class