Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Programming

Similar presentations


Presentation on theme: "Introduction to Computer Programming"— Presentation transcript:

1 Introduction to Computer Programming
1 Introduction to Computer Programming

2 Overview What is a computer? Components Units of storage Encoding
Hardware Software Units of storage Encoding

3 What is a computer? A computer is a collection of electrical and mechanical devices that can accept input and provide output via input and output devices respectively Processes data (input) to produce a result (output) Very fast execution of simple instructions Simple; example logic true and false, loops Combination of simple instructions generate more complex ones

4 Figure of a motherboard
Components Figure of a motherboard Hardware Internal devices Motherboard Interconnect internal devices Power supply Central Processing Unit (CPU) Speed in Hertz (Hz, cycles per second) Normally it is used the clock speed, in the order of GHz (1,000,000,000 Hz) CPU FDD: Floppy Disk Drive The CPU(s) needs to be close to motherboard to reduce distance to other devices like RAM that means bigger faster (quicker access) and less power consumption (heat produced – less important given the lengths considered)

5 Components Hardware Internal devices (cont.) Memory Volatile memory
Random Access Memory (RAM) Persistent memory Read Only Memory (ROM) Hard drive Data storage device (read/write) RAM Hard drive FDD: Floppy Disk Drive The CPU(s) needs to be close to motherboard to reduce distance to other devices like RAM that means bigger faster (quicker access) and less power consumption (heat produced – less important given the lengths considered)

6 Components CPU Power and data cables Power supply Ventilation Memory
Speaker Ventilation Memory Hard drive RAM Power supply Motherboard

7 Components Hardware (cont.) External also called peripherals
Input; provides data to the computer Keyboard Mouse Touch screen ... Output; gets data from the computer Monitor Printer Scanner External Storage Device Speakers Exercise: What other device is input and output? Touch screen and external memory device (e.g. USB stick, external mass storage device) are both input and output devices.

8 Components Software Basic Input/Output System (BIOS)
Instructions and setup for how a system should boot and how it operates Operating System (OS) Consists of programs that manage the computer hardware and resources, and provides common services for efficient execution of applications Programs Are a sequence of instructions written to perform a specified task Mainly the BIOS the following functions: POST – Tests the computer hardware, ensuring hardware is properly functioning before starting process of loading the operating system. Bootstrap Loader - Processes the location of the Operating System. If Operating System located, BIOS will pass the control to it. BIOS - Software / Drivers that interface between the operating system and your hardware. BIOS / CMOS Setup - It’s a configuration program that allows to configure hardware settings including system settings such as computer passwords, time, and date. BIOS and OS in machine language (has been compiled) to make them faster and more efficient. Programs may not like in the case of Java, we’ll see more in future lectures.

9 Units of storage Units of storage Bit Bytes Kilobytes (KB)
Two valid values 0 or 1 Bytes 8 bits Represents numbers from -128 to 127 (or 0 to 255) Kilobytes (KB) 1KB is 1024 Bytes Megabytes (MB) 1MB is 1024 KB Gigabytes (GB) 1GB is 1024 MB Terabytes (TB) 1TB is 1024 GB Machines represent integers with 4 Bytes (32 bits) or 8 Bytes (64 bits) 4 Bytes maximum integer represented is – to (normally used highest bit to represent the sign)

10 Encoding Encoding is the way a number may be represented
In the case of integers Decimal Ten values are used in the representation Uses 0, 1, ..., 9 to represent the number Binary Two values are used in the representation Uses 0 and 1 to represent the number Hexadecimal Sixteen values are used in the representation Uses 0, 1, ..., 9, a, b, ..., f to represent the number There are more representations, as octal, but the most used are decimal, binary and hexadecimal. 0 to 9 normally called digits

11 Encoding Binary 16 + 1 17 = Decimal Binary
Byte Decimal Binary (base 2) Bit Bit value 1 16 1 1 8 + 1 17 16 1 16 1 128 1 32 1 2 1 64 1 4 128 64 32 16 8 4 2 1 8 Bit index 7 6 5 4 3 2 1 20 21 22 27 23 26 25 24 Bit exponential representation /** * Builds the binary representation of the provided number. * iValue the number to represent in binary. the binary representation of the provided number. */ public static String toBin(final int iValue) { final String alpha = "01"; // representing values final int iRemainder = (iValue % 2); // amount left over String strBin; if (iValue == iRemainder) { // Last element in the representation strBin = alpha.charAt(iRemainde); } else { // Build next element in the representation strBin = toHex(iValue / 2) + alpha.charAt(iRemainder); } return strBin; } // toBin() 17 =    255

12 Encoding Hexadecimal 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 a b c d e f Dec Hex Divide by 16 Hexadecimal (base 16) 17 16 1 16 1 Byte 1 1 1 Divide by 16 255 5 16 16 1 5 255 Dec f ff Hex 9 One Byte is represented by two hexadecimal values, example ff for 255 or 7f for 127. Red Green Blue (RGB) colour representation, where each colour is represented in a byte in hexadecimal; white ffffff, red ff0000, green 00ff00 and blue 0000ff. The other values refers to mix of the tree main colours, red green and blue. /** * Builds the hexadecimal representation of the provided number. * iValue the number to represent in hexadecimal. the hexadecimal representation of the provided number. */ public static String toHex(final int iValue) { final String alpha = " ABCDEF"; // representing values final int iRemainder = (iValue % 16); // amount left over String strHex; if (iValue == iRemainder) { strHex = alpha.charAt(iRemainde); } else { strHex = toHex(iValue / 16) + alpha.charAt(iRemainder); } return strHex; } // toHex() 80 15 f f f 15

13 Encoding Examples Colour representation Red Green Blue (RGB) Purple
Three bytes one for each colour Purple D5F1C9 Examples 213 49 201 Black 000000 Absence of any colour Red FF0000 Just RED colour Green 00FF00 Just GREEN colour Blue 0000FF Just BLUE colour White FFFFFF WHITE colour Purple:

14 Encoding Examples (cont.)
American Standard Code for Information Interchange (ASCII) Encoding of characters and some symbols Just English alphabet Extended ASCII provides some extra Latin characters, for example Spanish ñ character Unicode Character Representations To support other languages it is required 2 bytes - called internationalisation Java uses Unicode Character Representation (16 bits representation)

15 Encoding ASCII DEC HEX BIN Symbol ... 53 35 5 74 4A J 95 5F _ 33 21 ! 54 36 6 75 4B K 96 60 ` 34 22 " 55 37 7 76 4C L 97 61 a 23 # 56 38 8 77 4D M 98 62 b 24 $ 57 39 9 78 4E N 99 63 c 25 % 58 3A : 79 4F O 100 64 d 26 & 59 3B ; 80 50 P 101 65 e 27 ' 3C < 81 51 Q 102 66 f 40 28 ( 3D = 82 52 R 103 67 g 41 29 ) 3E > 83 S 104 68 h 42 2A * 3F ? 84 T 105 69 i 43 2B + @ 85 U 106 6A j 44 2C , A 86 V 107 6B k 45 2D - B 87 W 108 6C l 46 2E . C 88 X 109 6D m 47 2F / D 89 Y 110 6E n 48 30 E 90 5A Z 111 6F o 49 31 1 70 F 91 5B [ 112 p 32 2 71 G 92 5C \ 113 q 3 72 H 93 5D ] 114 r 4 73 I 94 5E ^ a A A byte represent a character in ASCII but just in English alphabet, the extended ASCII cover other characters like Latin (Spanish). Need to use 2 bytes to be able to represent all languages in the world. Java has build-in support for internalisation. /** * Builds the binary representation of the provided number. * iValue the number to represent in binary. iBase the base of the encoding, form 2 (binary) to 16 (hexadecimal). the binary representation of the provided number. IllegalArgumentException when an invalid encoding base is provided. */ public static String toEncode(final int iValue, final int iBase) { if (iBase < 2 || iBase > 16) { // Runtime exception so does't need to be specified in the method declaration throw new IllegalArgumentException("Invalid encoding base of " + iBase + " that should be bigger or equal to 2 and smaller or equal" + " to 16"); } final String alpha = " ABCDEF"; // representing values final int iRemainder = (iValue % iBase); // amount left over String strRepresentation; if (iValue == iRemainder) { // Last element in the representation strRepresentation = alpha.charAt(iRemainde); } else { // Build next element in the representation strRepresentation = toHex((iValue/iBase), iBase) + alpha.charAt(iRemainder); return strRepresentation; } // toEncode()


Download ppt "Introduction to Computer Programming"

Similar presentations


Ads by Google