Lecture 2 Binary Number Systems 3. HardwareandSoftw are 4. - - PDF document

lecture 2
SMART_READER_LITE
LIVE PREVIEW

Lecture 2 Binary Number Systems 3. HardwareandSoftw are 4. - - PDF document

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


slide-1
SLIDE 1

1

1. Introduction 2. BinaryRepresentation 3. HardwareandSoftw are 4. HighLevel Languages 5. Standard inputand output 6. Operators, expression and statem ents 7. M akingDecisions 8. Looping 9. Arrays 10. Basicsof pointers 11. Strings 12. Basicsof functions 13. M

  • reabout functions

14. Files 14. DataStructures 16. Casestudy:lotterynum bergenerator

Lecture 2

Binary Number Systems

  • Decimal is a base 10 number system

– 1’s, 10’s, 100’s, 1000’s etc

  • Binary is just a base 2 number system

– 1, 2, 4, 8, 16 etc

  • A binary variable can have 2 states

– 1/0, on/off, +5v/0v

  • For example, the binary equivalent of the

decimal number 26 is 11010,

which is 11010 = 1x24 + 1x23 + 0x22 + 1x21 + 0x20

Binary Number Systems

  • bit

– One binary digit 0 or 1.

  • byte

– A group of 8 bits capable of representing binary numbers from 0-255 i.e. 10010101

  • nibble

– A group of 4 bits, i.e. 1001

  • word

– Most computer systems organise their memories in groups of bytes called words. An eight-bit word consists of one byte, a sixteen-bit word consists of two bytes, a thirty-two-bit word consists of four bytes, and so on.

Other Number Systems

  • Hexadecimal and Octal Number Systems

– Binary numbers are a convenient representation for manipulation by digital computers, but not by human beings. It is often advantageous to convert a binary number into its hexadecimal (base 16) or octal (base 8) representation. The following table shows the representation of numbers in decimal, binary, octal and hexadecimal.

Decimal Binary Octal Hexadecimal 00 0000 00 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F

Number System Conversion

e.g. the decimal value 77 is represented as a binary byte thus 7710 = 0100 1101 and in hexadecimal and octal as 4D and 115 respectively 0100 1101 01 001 101 4 D 1 1 5 By knowing the binary code for hexadecimal and octal digits, the binary code for multi-byte numbers can be easily constructed. The binary representation of the four byte value #1EA7 (where # denotes hexadecimal) is 0001 1110 1010 0111 1 E A 7

Logical Operations on Binary Number Systems

A B f 1 1 1 1 1 A B f 1 1 1 1 1 1 1 A f 1 1 A B f 1 1 1 1 1 1

slide-2
SLIDE 2

2

Adding Binary Numbers

  • Performs the function of a half adder

– adds 2 binary numbers together

AB C B A B A S = + =

A B Sum Carry 1 1 1 1 1 1 1

Dear Sir I am writing with regards to……. 10111011011 1001011010011 101011……...

How to we get from text, images, sound and movies to a language the computer can understand ?

Characters

  • Most common standard for representing

characters is ASCII, 7 bit code 27=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 e 101 1100101 65 y 121 1111001 79 . 46 0101110 2E

Sound

  • Waveforms can be digitised by sampling the waveform at

regular intervals producing a binary, discrete representation

  • f a continuous signal

Images and Movies

  • An intensity image is represented as a

rectangular array of pixels, where each pixel has an intensity value.

Algorithms

process get_drunk: repeat

buy-lager

  • pen-can

repeat

lift-to-mouth swallow

until can-is-empty

until no-money OR paralytic

slide-3
SLIDE 3

3

Algorithms

  • Each instruction in the instruction set

can be represented by an arbitrary binary code.

  • 2 volunteers

Algorithms

  • You are Address 0.
  • Obey only instructions sent to Address 0
  • Stay facing the audience
  • Instruction set:

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

  • You are Address 1.
  • Obey only instructions sent to Address 1
  • Stay facing the audience
  • Instruction set:

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

Address Instruction 1 1 1 1 1 1 1 1 1 1 1 1 Student 0 stage left Student 1 stage right

swap places swap back

Algorithms

ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01 ADD INST 01 1 11 00 1 11 1 10 1 01 01 1 11 11 00 00 1 01 10 11 1 01 1 01 1 11 10 1 01 11 00 1 11 1 11 01 1 01 01

BOOKS

  • Recommended course book:

– Sams Teach Yourself C in 21 Days, by Peter Aitken and Bradley L. Jones, Sams Publishing – Sams Teach Yourself C in 24 Hours (2nd edition), by Tony Zhang, Sams Publishing – C - A Reference Manual (4th edition), by Samuel Harbison and Guy Steele, Prentice Hall

  • Other Books

– Structured Computer Organisation by Andrew S Tanenbaum, Prentice Hall – C How to Program, by Harvey Deitel and Paul Deitel, Prentice Hall – C Programming Language (2nd Edition) by Brian Kernigham and Dennis Ritchie, Prentice Hall. – C Program Design for Engineers, by Hanly, Koffman and Horvath, Addison-Wesley – Beginners Guide to C, by Ivor Horton, VVrox Press