1. Introduction 2. BinaryRepresentation Lecture 2 Binary Number Systems 3. HardwareandSoftw are 4. HighLevel Languages 5. Standard inputand output • Decimal is a base 10 number system 6. Operators, expression and statem ents – 1’s, 10’s, 100’s, 1000’s etc 7. M akingDecisions • Binary is just a base 2 number system 8. Looping 9. Arrays – 1, 2, 4, 8, 16 etc 10. Basicsof pointers • A binary variable can have 2 states 11. Strings – 1/0, on/off, +5v/0v 12. Basicsof functions • For example, the binary equivalent of the 13. M oreabout functions decimal number 26 is 11010, 14. Files which is 11010 = 1x2 4 + 1x2 3 + 0x2 2 + 1x2 1 + 0x2 0 14. DataStructures 16. Casestudy:lotterynum bergenerator Binary Number Systems Other Number Systems • Hexadecimal and Octal Number Systems • bit – Binary numbers are a convenient representation for manipulation by – One binary digit 0 or 1. digital computers, but not by human beings. It is often advantageous to • byte convert a binary number into its hexadecimal (base 16) or octal (base 8) representation. – A group of 8 bits capable of representing binary numbers from 0-255 i.e. 10010101 Decimal Binary Octal Hexadecimal The following table shows the 00 0000 00 0 • nibble representation of numbers in 01 0001 01 1 02 0010 02 2 – A group of 4 bits, i.e. 1001 decimal, binary, octal and 03 0011 03 3 hexadecimal. • word 04 0100 04 4 05 0101 05 5 06 0110 06 6 – Most computer systems organise their memories in groups of bytes 07 0111 07 7 called words. An eight-bit word consists of one byte, a sixteen-bit 08 1000 10 8 word consists of two bytes, a thirty-two-bit word consists of four 09 1001 11 9 10 1010 12 A bytes, and so on. 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F Logical Operations on Binary Number System Conversion Number Systems A B f e.g. the decimal value 77 is represented as a binary byte thus 0 0 0 77 10 = 0100 1101 0 1 0 and in hexadecimal and octal as 4D and 115 respectively 1 0 0 1 1 1 0100 1101 01 001 101 A B f 4 D 1 1 5 0 0 0 0 1 1 By knowing the binary code for hexadecimal and octal digits, the binary code for multi-byte numbers can be easily constructed. 1 0 1 1 1 1 The binary representation of the four byte value #1EA7 (where # denotes hexadecimal) is A f 0001 1110 1010 0111 0 1 1 E A 7 1 0 A B f 0 0 0 0 1 1 1 0 1 1 1 0 1
Adding Binary Numbers Dear Sir How to we get from text, images, sound and movies to a language the computer I am writing with can understand ? 10111011011 regards to……. = + 1001011010011 S A B A B 101011……... = C AB • Performs the function of a half adder – adds 2 binary A B Sum Carry numbers together 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 Characters Sound • Most common standard for representing characters is ASCII, 7 bit code 2 7 =128 – American Standard Code for Information Interchange eg. dec binary hex s 83 1010011 53 u 117 1110101 75 r 114 1110010 72 r 114 1110010 72 • Waveforms can be digitised by sampling the waveform at e 101 1100101 65 regular intervals producing a binary, discrete representation y 121 1111001 79 . 46 0101110 2E of a continuous signal Images and Movies Algorithms • An intensity image is represented as a process get_drunk: rectangular array of pixels, where each pixel repeat has an intensity value. buy-lager open-can repeat lift-to-mouth swallow until can-is-empty until no-money OR paralytic 2
Algorithms Algorithms • Each instruction in the instruction set • You are Address 0. can be represented by an arbitrary • Obey only instructions sent to Address 0 binary code. • Stay facing the audience • Instruction set: • 2 volunteers 0 0 Walk forward 2 step 0 1 Walk backward 2 steps 1 0 Walk left 2 steps 1 1 Walk right 2 steps Algorithms Algorithms Address Instruction • You are Address 1. 0 0 0 • Obey only instructions sent to Address 1 1 1 0 swap places 0 1 1 • Stay facing the audience 0 0 1 • Instruction set: 1 0 0 0 1 0 0 0 Walk forward 2 step swap back 1 1 1 0 1 Walk backward 2 steps 1 0 1 1 0 Walk left 2 steps 1 1 Walk right 2 steps Student 0 stage left Student 1 stage right BOOKS Algorithms • Recommended course book: ADD INST ADD INST ADD INST ADD INST ADD INST ADD INST ADD INST ADD INST ADD INST – Sams Teach Yourself C in 21 Days, by Peter Aitken and Bradley L. 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 Jones, Sams Publishing 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 – Sams Teach Yourself C in 24 Hours (2nd edition), by Tony Zhang, 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 10 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 Sams Publishing 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 – C - A Reference Manual (4th edition), by Samuel Harbison and Guy 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 Steele, Prentice Hall 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 0 10 0 10 0 10 0 10 0 10 0 10 0 10 0 10 0 10 • Other Books 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 – Structured Computer Organisation by Andrew S Tanenbaum, 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 Prentice Hall 0 10 0 10 0 10 0 10 0 10 0 10 0 10 0 10 0 10 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 – C How to Program, by Harvey Deitel and Paul Deitel, Prentice Hall 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 11 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 0 00 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 – C Programming Language (2nd Edition) by Brian Kernigham and 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 1 11 Dennis Ritchie, Prentice Hall. 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 1 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 0 01 – C Program Design for Engineers, by Hanly, Koffman and Horvath, Addison-Wesley – Beginners Guide to C, by Ivor Horton, VVrox Press 3
Recommend
More recommend