introduction to computers

41
Introduction to computers and programming

Upload: visualbeecom

Post on 26-May-2015

547 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to computers

Introduction to computers and programming

Page 2: Introduction to computers

Content

• Hardware• Information storage

RAM, ROM HD, DVD

• Display Images Characters (fonts)

• File system/type Encryption Compression

• Network Protocols Packets

• Programming Algorithm Pseudocode Flowchart

• Languages• Source code

Example

Page 3: Introduction to computers

The computer

Page 4: Introduction to computers

Internally

Page 5: Introduction to computers

The connections

Page 6: Introduction to computers

Information storage

• 1 bit• 8 bits• 16 bits• 32 bits• 64 bits

• bit (1 or 0)• byte (octet) (28)• word (216)• double (232)• long double

(264)

Encoding information on a fixed element of length n with a base b gives bn non-redundant possibilities

Page 7: Introduction to computers

Information coding

• Binary 0 or 1

• Octal 0-7

• Hexadecimal 0-9+A-F

• Decimal 0-9

• How to count

• 128+32+16+4+1= 181 (decimal) 265 (octal) B5 (hexadecimal)

• Signed vs unsigned 0 to 255 -127 to +127

128 64 32 16 8 4 2 1

1 0 1 1 0 1 0 1

Page 8: Introduction to computers

Operations on bits

• Booleans: 0 = false = no 1 = true = yes

• Operators: AND OR XOR NOT

• Example tablesAND

0 1

0 0 0

1 0 1

OR 0 1

0 0 1

1 1 1

XOR 0 1

0 0 1

1 1 0

Page 9: Introduction to computers

RAM/ROM

Memory mappingAddress Values0000 00010002......

..FFFF

• Size reminder:• Kilobyte Kb 210

~103

• Megabyte Mb 220

~106

• Gigabyte Gb 230

~109

• Terabyte Tb 240

~1012

• Petabyte Pb 250

~1015

• …

1 0 1 1 1 0 0 1

0 0 0 0 1 1 1 1

1 1 1 0 0 0 1 1

0 0 1 0 0 1 0 0

Page 10: Introduction to computers

HD/DVD

track

sector

head

Page 11: Introduction to computers

Display

• Screen pixel or dots• Color coding: 32 bits• 1 pixel = 3 bytes of color (RGB)+1 byte alpha channel

(transparency)• 1600x1200x4bytes=7,5 Mb!

• Fonts Bitmap Vectors

TrueType, OpenType, PostScript

QuickTime™ et undécompresseur TIFF (non compressé)

sont requis pour visionner cette image.

Page 12: Introduction to computers

Keyboard/Mouse

• Each key (or combination of keys) of the keyboard sends a code to the computer.

• The code is interpreted and converted to the corresponding ASCII or Unicode number.

• The mouse movements 1 to 4 bytes (vertical &

horizontal)

• Buttons Clicked, pressed, rolled

buttons

Page 13: Introduction to computers

ASCII & Unicode

• ASCII 7/8 bits• Unicode

UTF-8/16/32 bits ISO-8859 (Latin)

• od -c od -h

Page 14: Introduction to computers

Software layers

ROM

Hardware

Operating System

User Interface

Software

Files

CPU, RAM, HD, DVD

Word, scripts, mail, web browser…

Data (.doc, .mp3)

BIOS

Linux

CLI, X-Windows

Windows

Windows

MacOSX

Firmware

Quartz

Page 15: Introduction to computers

File systems

• Method the OS uses to store information Storage unit, directories, subdirectories

(Windows, VMS) Single arborescence (Linux, MacOSX, all Unix)

• What exactly is a file? a piece of information (text, graphic, data,

music program, script) it is identified by a name and an logical

address (or path) other informations: date, size, type, creator,

ownership, physical address…

Page 16: Introduction to computers

File system organisation

Disk 1 Disk 2

Directories

Subdirectories

Windows

DOCS PROGS

WORD EXCEL

CONFIG DATA

EXPT1 EXPT2

/

/usr /home

phil johnlocal

bin lib

emacs X11

Unix

D:C:

Disk 1

Disk 2

Page 17: Introduction to computers

Path

• The path is the logical address used by the system or the user to locate a file.

• Example:/bd_du_Palais/35/etage/4/appart/12/Dupont_ Jean.txt

filenamesuffix

path

Page 18: Introduction to computers

File types

• Executable .exe .app Unix requires « x »

• Data Text (.txt) Music (.mp3) Image (.jpg, .gif) Movie (.mpg, .mov) Binary (.bin)

• Special cases in Unix STDIN STDOUT STDERR

Page 19: Introduction to computers

Encryption / compression

• Compression Reducing the size of files E.g., .mp3, .gz, .jpg, .zip

• Encryption Protecting your privacy E.g., .pgp

• Packing Grouping the files E.g., .tar

Page 20: Introduction to computers

Networks

• Direct USB 11Mb-480Mb Ethernet 10Mb-1Gb

• Wired Modem 56Kb ADSL 600Kb-8Mb LAN 10Mb-10Gb

• Wireless Bluetooth 1Mb-20Mb WIFI (AirPort) 11Mb-54Mb

Page 21: Introduction to computers

Network (ethernet or wireless)

• Computer talk to each other via network protocols ip, tcp, http, ftp, …

• TCP/IP transmission control

protocol/internet protocol

• Handshaking• Transmission• Ackowledgement

• DNS Domain Name Server

• URL Universal Resource

Locator• IP addess

192.42.197.51

Page 22: Introduction to computers

DNS reminder

Primary DNS

Root DNS

Local DNS

Client query Target server

1

2 3

45

6

www.expasy.org

129.194.8.64

*.org

dns.anywhere.net

client.anywhere.net

www.expasy.org ??

Page 23: Introduction to computers

Packets

The data travels within units called packets

Page 24: Introduction to computers

Packet breakout

Usual TCP/IP payload per packet: 512 bytes

Page 25: Introduction to computers

Introduction to programming

Page 26: Introduction to computers

What is a program?

• How to cook?• The algorithm• Are you a programmer?

Page 27: Introduction to computers

Pseudocode

• This is the pseudocode for a game of Monopoly

Page 28: Introduction to computers

Flowcharts

Page 29: Introduction to computers

Flowcharts details

Page 30: Introduction to computers

Languages

• Low level (processor dependent) Machine code, assembler

• High level: structured, procedural Fortran, C, Pascal…

• High level: object oriented C++, Java, C#, Perl, Objective-C…

• Virtual machines Java, C#…

• Scripting Perl, Python, JavaScript…

Page 31: Introduction to computers

Source code -> Object code

• Compiler+linker Fortran, C, Pascal, C++…

• Interpreter Basic, Perl…

• Intermediate Java

• Compiler+linker Fast to execute, but

slow to debug• Interpreter

Slow to execute, but fast to debug (no need to recompile)

• Intermediate Slow…

Page 32: Introduction to computers

Source code

• Instructions Statement, blocks Affectation Operators Loops Tests Subroutines Comments

• Data structures Variable List Array Hash Pointers Objects

Page 33: Introduction to computers

Source code (2)

• Statement, blocks One or more instructions for the

processor• Affectation

Change to a variable• Operator

affect one or more variable + * - / AND OR NOT…

• Variable A region in memory that can be

modified Exists in different types

Scalar, char, numeric, boolean List, array Hash Combination->data structure

Page 34: Introduction to computers

Source code (3)

• Loops Allow the

computer to repeat blocks

• Tests Decide what to

do• Subroutines

Programs frequently called (functions)

• Comments The most

important lines of the source code…

• Pointers Reference to region in memory

(address)

• Objects Combination of data and code

Page 35: Introduction to computers

Example: a text to treat

« Noon rings out. A wasp, making an ominous sound, a sound akin to a klaxon or a tocsin, flits about. Augustus, who has had a bad night, sits up blinking and purblind. Oh what was that word (is his thought) that ran through my brain all night, that idiotic word that, hard as I'd try to pun it down, was always just an inch or two out of my grasp - fowl or foul or Vow or Voyal? - a word in a quizz which, by association, brought into play an incongruous mass and magma of nouns, idioms, slogans and sayings, a confusing, amorphous outpouring which I sought in vain to control or turn off but which wound around my mind a whirlwind of a cord, a whiplash of a cord, a cord that would split again and again, would knit again and again, of words without communication or any possibility of combination, words without pronunciation, signification or transcription but out of which, notwithstanding, was brought forth a flux, a continuous, compact and lucid flow: an intuition, a vacillating frisson of illumination as if caught in a flash of lightning or in a mist abruptly rising to unshroud an obvious sign - but a sign, alas, that would last an instant only to vanish for good. »

Gilbert Adair

Page 36: Introduction to computers

Result…

a=97b=15c=26d=35f=23g=32h=44i=90j=1k=5l=33m=17

n=91o=104p=15q=1r=43s=59t=77u=52v=4w=31x=2y=13z=2

Do you see any problem??

Try with this:

« The quick brown fox, jumps over the lazy dog. »

Page 37: Introduction to computers

Flowchart

Page 38: Introduction to computers

Source code example

#!/usr/bin/perl -w # essential line of all perl scripts

$filename = "avoid.txt"; # affect « avoid.txt » to the variable $filename

# open the file, or exitopen(FILE, $filename) || die "Cannot open file ‘$filename’\n\n";@text = <FILE>; # add each line of the file to an arrayclose FILE;

foreach $line (@text) { # read one line from the array into $line and repeat for each line @table = split(//,$line); # read each character of the line in an array while ($char=pop(@table)) { # read one character of the array 'table' and repeat for all

$char =~ s/[^a-z]//; # keep only the alphabetical character a to z if ($char) { # check if the character exists and execute the block

$count{$char}++; # if yes, increment by one the hash 'count' }

} }

# print each character and its number of occurence one per lineforeach $c (keys %count) {

print "$c=$count{$c}\n";}exit; # quit the program

Page 39: Introduction to computers

Tips

• Think about your problem• Create a flowchart• Create the pseudocode• Verify the memory used by your

variables• Write the code

• Test the code For all the possible functions or cases (if

possible) Give it to users as a beta (if not possibe) Sell it (if you work for Microsoft©… ;-)

• Debug

Page 40: Introduction to computers

Summary of the week

• Monday Intro computers & programming Intro Unix Tutorial Unix

• Tuesday Intro Perl Regexp & Perl In-liners

• Wednesday Object Oriented programming BioPerl EMBOSS

• Thursday Database indexing BLAST HTML & cgi-bin

• Friday Finish exercises Users questions

Page 41: Introduction to computers

Unix

• Next presentation…

Vassilios alias

UnixMan!!!