Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for...
-
date post
22-Dec-2015 -
Category
Documents
-
view
225 -
download
0
Transcript of Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for...
Introduction to Introduction to Computers and Computers and ProgrammingProgramming
Some definitionsSome definitions
Algorithm:Algorithm: A procedure for solving a problemA procedure for solving a problem A sequence of discrete steps that A sequence of discrete steps that
defines such a procedure, or methoddefines such a procedure, or method Computer Science:Computer Science:
Finding solutions to problems with the Finding solutions to problems with the aid of computersaid of computers
The study of algorithmsThe study of algorithms
HardwareHardware
Physical parts of a computer systemPhysical parts of a computer system Major components include:Major components include:
CPUCPU MemoryMemory Peripheral devicesPeripheral devices
CPUCPU
CPU consists of the control unit, the CPU consists of the control unit, the ALU, and registersALU, and registers registers: high-speed memory cellsregisters: high-speed memory cells ALU: arithmetic logic unit; performs ALU: arithmetic logic unit; performs
calculationscalculations control unit: copies data & instructions control unit: copies data & instructions
from memory, decodes instructions and from memory, decodes instructions and follows themfollows them
Main memoryMain memory Stores data & instructions in bit Stores data & instructions in bit
formform data: information to be processeddata: information to be processed instructions: commands for instructions: commands for
computer to followcomputer to follow bits: binary digits; two states bits: binary digits; two states
represented as 1 or 0represented as 1 or 0 Memory is organized into 8-bit Memory is organized into 8-bit
groups called bytesgroups called bytes Each byte has its own unique Each byte has its own unique
addressaddress
Memory representationMemory representation
Each instruction or piece of data Each instruction or piece of data must be stored in one or more bytes must be stored in one or more bytes of memoryof memory
The arrangement of 1s and 0s in The arrangement of 1s and 0s in each 8-bit byte can be interpreted as each 8-bit byte can be interpreted as code representing a single code representing a single instruction or data iteminstruction or data item
Many data items and instructions Many data items and instructions require more than one byte of require more than one byte of memory; we’ll see why latermemory; we’ll see why later
Memory sizeMemory size We typically discuss memory in We typically discuss memory in
increments of millions (megabytes) or increments of millions (megabytes) or billions (gigabytes)billions (gigabytes)
In fact, since the fundamental building-In fact, since the fundamental building-block of memory is the byte, which is in block of memory is the byte, which is in turn based on the bit, the actual size of turn based on the bit, the actual size of what we call a megabyte isn’t really a what we call a megabyte isn’t really a million bytes, but the closest power of 2: million bytes, but the closest power of 2: 222020, or 1,048,576, or 1,048,576
Likewise, a gigabyte is actually 2Likewise, a gigabyte is actually 23030 bytes, bytes, which is 1,073,741,824which is 1,073,741,824
SoftwareSoftware
Consists of programs that can run on Consists of programs that can run on a computera computer Applications programsApplications programs System programsSystem programs
A program is a set of instructionsA program is a set of instructions Data are the raw material: letters Data are the raw material: letters
and numbers, for exampleand numbers, for example
Character data Character data representationrepresentation
Bit patterns are used to represent Bit patterns are used to represent characters and symbolscharacters and symbols
ASCII is a code system that matches ASCII is a code system that matches 8-bit patterns with natural language 8-bit patterns with natural language symbols, such as letters, numbers, symbols, such as letters, numbers, and punctuation marks; a total of 256 and punctuation marks; a total of 256 characters (2characters (288) can be represented) can be represented
Unicode, a 16-bit system, is used in Unicode, a 16-bit system, is used in Java: this provides support for Java: this provides support for multiple languages and alphabetsmultiple languages and alphabets
Integer data Integer data representationrepresentation
Integers, or whole numbers, are represented Integers, or whole numbers, are represented using the binary, or base 2, numbering systemusing the binary, or base 2, numbering system
As in the more familiar base 10, or decimal As in the more familiar base 10, or decimal notation, a 0 digit represents a placeholder; notation, a 0 digit represents a placeholder; other digits should be multiplied by the other digits should be multiplied by the corresponding power the base, starting with corresponding power the base, starting with the 0th power for the rightmost digit, the 1st the 0th power for the rightmost digit, the 1st power for the next one, the 2nd for the next, power for the next one, the 2nd for the next, etc.etc.
The sum of the digits multiplied by their The sum of the digits multiplied by their respective base powers is the value of the respective base powers is the value of the numbernumber
Decimal exampleDecimal example
The number 12,486 can be read (left to The number 12,486 can be read (left to right) as:right) as:(1 x 10(1 x 1044) + (2 x 10) + (2 x 1033) +(4 x 10) +(4 x 1022) + (8 x 10) + (8 x 1011) + (6 x 10) + (6 x 1000) = ) =
10000 + 2000 + 400 + 80 + 610000 + 2000 + 400 + 80 + 6
For binary numbers, the principle works For binary numbers, the principle works the same, except that only 1s and 0s are the same, except that only 1s and 0s are used, and the digit at each place is used, and the digit at each place is multiplied by 2 instead of 10; the sum is multiplied by 2 instead of 10; the sum is still the value (in base 10) of the numberstill the value (in base 10) of the number
Binary exampleBinary example
The number 11000110The number 1100011022 can be read as: can be read as:(1 x 2(1 x 277) + (1 x 2) + (1 x 266) + 0 + 0 + 0 + (1 x 2) + 0 + 0 + 0 + (1 x 222) + (1 x 2) + (1 x 211) + 0 = ) + 0 =
128 + 64 + 4 + 2 = 198128 + 64 + 4 + 2 = 1981010
Using binary representation requires several Using binary representation requires several more digits than does decimalmore digits than does decimal
The largest number that can be represented in 8 The largest number that can be represented in 8 bits is 11111111bits is 1111111122, or 255, or 2551010
If one bit is reserved for the sign (positive or If one bit is reserved for the sign (positive or negative), than the magnitude of the number is negative), than the magnitude of the number is restricted to restricted to 2 277-1 (127-1 (1271010))
Integer representationInteger representation
The number of bits used determines The number of bits used determines the magnitude of the numbers that the magnitude of the numbers that can be storedcan be stored
Signed numbers have more Signed numbers have more restricted magnitude than unsigned restricted magnitude than unsigned numbersnumbers
Representing real Representing real numbersnumbers
Like integers and characters, real Like integers and characters, real numbers are stored in binary formnumbers are stored in binary form
Unlike integers, real numbers are Unlike integers, real numbers are represented using scientific notation:represented using scientific notation: in decimal, the number 12345 can be in decimal, the number 12345 can be
represented as 1.2345 x 10represented as 1.2345 x 1044, abbreviated , abbreviated 1.2345e41.2345e4
similarly, .00025 is represented as 2.5e-4similarly, .00025 is represented as 2.5e-4
Representing real Representing real numbersnumbers
In computers, binary notation is usedIn computers, binary notation is used Since binary numbers are composed of 0s Since binary numbers are composed of 0s
and 1s, any number can be represented and 1s, any number can be represented with a whole part of 1; so it isn’t with a whole part of 1; so it isn’t necessary to store a number’s whole part, necessary to store a number’s whole part, as it is always 1as it is always 1
Therefore, several bits can be set aside to Therefore, several bits can be set aside to represent the fractional part of the represent the fractional part of the mantissa, and several more bits can be mantissa, and several more bits can be used to represent the exponent of the used to represent the exponent of the radix, 2radix, 2
Representing real Representing real numbersnumbers
Both the mantissa (its fractional Both the mantissa (its fractional part) and the exponent are stored; part) and the exponent are stored; total number of bits is apportioned total number of bits is apportioned between the two partsbetween the two parts
Both components have a sign bitBoth components have a sign bit Number of bits used restricts both Number of bits used restricts both
the magnitude and the precision of the magnitude and the precision of the number to be represented; real the number to be represented; real numbers are always approximationsnumbers are always approximations
Representation of Representation of InstructionsInstructions
Instruction set: set of operations a Instruction set: set of operations a particular processor can performparticular processor can perform Specific to each hardware platformSpecific to each hardware platform Encoded as binary digitsEncoded as binary digits
Programming language: language in Programming language: language in which a program is written; consists which a program is written; consists of a set of symbols and the rules for of a set of symbols and the rules for their usetheir use
Low-level languagesLow-level languages
Low-level languages operate at a low Low-level languages operate at a low level of abstraction: that is, level of abstraction: that is, individual symbols have a simple, individual symbols have a simple, well-defined, specific meaningwell-defined, specific meaning
Low-level languages operate at or Low-level languages operate at or close to the level of the computer’s close to the level of the computer’s instruction set; that is, the set of instruction set; that is, the set of commands a processor is wired to commands a processor is wired to respond torespond to
Low-level languagesLow-level languages
Specific and simple instructions, non-Specific and simple instructions, non-abstractabstract
Platform-specific and non-portablePlatform-specific and non-portable Difficult for humans to read and writeDifficult for humans to read and write Include machine and assembly Include machine and assembly
languageslanguages Programs tend to be long, as each Programs tend to be long, as each
instruction is extremely specificinstruction is extremely specific
High-level languagesHigh-level languages
High-level languages exist at a High-level languages exist at a higher level of abstraction; higher level of abstraction; individual instructions are often individual instructions are often equivalent to several low-level equivalent to several low-level instructionsinstructions
High-level languages are closer to High-level languages are closer to the natural languages humans use to the natural languages humans use to communicatecommunicate
High-level languagesHigh-level languages
High-level language programs require High-level language programs require translation to machine language before translation to machine language before they can be executed by a computerthey can be executed by a computer
As long as you have the software to do As long as you have the software to do the translation, you can run a high-the translation, you can run a high-level language program on any kind of level language program on any kind of computer - thus, high-level languages computer - thus, high-level languages are said to portable and platform non-are said to portable and platform non-specificspecific
High-level languagesHigh-level languages
Because the language is more Because the language is more abstract, a high-level language abstract, a high-level language program tends to be much shorter program tends to be much shorter than its low-level counterpartthan its low-level counterpart
Most well-known languages are Most well-known languages are high-level languages - these include high-level languages - these include C, C++, Java, FORTRAN, BASIC, C, C++, Java, FORTRAN, BASIC, COBOL, Pascal, python, Ada, etc.COBOL, Pascal, python, Ada, etc.
High-level languagesHigh-level languages
AbstractAbstract PortablePortable Relatively easy for humans to read Relatively easy for humans to read
and writeand write Include most “named” languagesInclude most “named” languages Programs relatively briefPrograms relatively brief Require translation to make Require translation to make
executableexecutable
Programming Language Programming Language TranslationTranslation
Interpreters: perform line-by-line Interpreters: perform line-by-line translation and execution of a translation and execution of a programprogram
Compilers: translate entire program Compilers: translate entire program into machine language prior to into machine language prior to executionexecution
Java is unique: uses both methodsJava is unique: uses both methods