Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2: Representing Numbers CS 2011 Fall 2014, Dr. Rozier.

Similar presentations


Presentation on theme: "Lecture 2: Representing Numbers CS 2011 Fall 2014, Dr. Rozier."— Presentation transcript:

1 Lecture 2: Representing Numbers CS 2011 Fall 2014, Dr. Rozier

2 LADIES AND TIGERS

3 The Lady and the Tiger Two doors containing either Ladies or Tigers

4 The Lady and the Tiger You will be shown two doors, to two rooms. – Each could contain either a lady or a tiger… – It could be that both rooms contain a lady, or that both rooms contain a tiger! You will need to reason carefully and logically to survive! Each question, pick a door, or decide not to open a door. – You score one point for picking a lady, or for refusing to pick if both doors contain tigers. – Three points available for your homework/projects grade today – If you answer wrong, you may write a short paper describing what you did wrong, and how to find the right answer, due next class.

5 The Lady and the Tiger Form up into groups On a sheet of paper, list the first and last names of each student in the group, and pick a team name – Discuss your answers, and record them – Each group will then give their answers to the class

6 The Lady and the Tiger Q1 One of these is true… In this room, there is a lady, and in the other room there is a tiger. The other is false… In one of these rooms there is a lady, and in one of these rooms there is a tiger.

7 The Lady and the Tiger Q1 One of these is true…The other is false…

8 The Lady and the Tiger Q2 Either both signs are false… At least one of these rooms contains a lady Or both are true… A tiger is in the other room…

9 The Lady and the Tiger Q2 Either both signs are false…Or both are true…

10 The Lady and the Tiger Q3 Either both signs are false… Either a tiger is in this room, or a lady is in the other room. Or both are true… An lady is in the other room.

11 The Lady and the Tiger Q3 Either both signs are false…Or both are true…

12 What does this have to do with CS?

13 CS and CE What are the disciplines? – Computer Engineering? – Computer Science?

14 What it isn’t "What would we like our children- the general public of the future—to learn about computer science in schools? We need to do away with the myth that computer science is about computers. Computer science is no more about computers than astronomy is about telescopes, biology is about microscopes or chemistry is about beakers and test tubes. Science is not about tools, it is about how we use them and what we find out when we do." -- Ian Parberry

15 What it isn’t A confusion of even longer standing came from the fact that the unprepared included the electronic engineers that were supposed to design, build, and maintain the machines. The job was actually beyond the electronic technology of the day, and, as a result, the question of how to get and keep the physical equipment more or less in working condition became in the early days the all-overriding concern. As a result, the topic became —primarily in the USA— prematurely known as "computer science" —which, actually is like referring to surgery as "knife science"— and it was firmly implanted in people's minds that computing science is about machines and their peripheral equipment. -- Edsger Dijkstra

16 What it really is Computer science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems. Computer scientists invent algorithmic processes that create, describe, and transform information and formulate suitable abstractions to model complex systems. Computer engineering is the process of analyzing, designing, and integrating the hardware and software systems needed for information processing or computation. Computer engineers are saddled with the difficult tasks of modeling, designing, and analyzing cyberphysical systems which solve interdisciplinary problems in a wide variety of domains.

17 REPRESENTING NUMBERS

18 How can we represent numbers in a computer? What limitations do we face? What requirements do we have?

19 Networking and Communication What if we encode the signal into pulses? Detect if the value is above or below some threshold, and decide it represents a 1, or a 0. Strings of 1’s and 0’s can be interpreted as a number.

20 Some simple things we can represent with 1’s and 0’s True or false… – 1 – true – 0 – false – We already were doing this with pure signals.

21 Some simple things we can represent with 1’s and 0’s Integers Examples – 00000000 – 0- 00000010 - 2 – 00000001 – 1- 00001010 – 10 – 00000011 – 3- 10010011 – 147

22 Unsigned Binary Integers Given an n-bit number Range: 0 to +2 n – 1 Example 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + … + 1×2 3 + 0×2 2 +1×2 1 +1×2 0 = 0 + … + 8 + 0 + 2 + 1 = 11 10 Using 32 bits 0 to +4,294,967,295

23 Binary and Hexadecimal Because binary numbers are rather unwieldy, programmers prefer to use a more compact way to represent them. Historically, octal (base 8) and hexadecimal (base 16, or hex) have been used. – Octal has the advantage that it uses only familiar digits, but it groups digits by threes, which is inconvenient for word sizes that are multiples of 4. So it is seldom used nowadays. – Hexadecimal works nicely for bytes and for word sizes that are multiples of 4, but requires the introduction of 6 new digits. Conversion between binary and decimal is slow and is preferably avoided if there is no need. Octal and hex allow immediate conversion to and from binary.

24 Hexadecimal Base 16 – Compact representation of bit strings – 4 bits per hex digit 000004010081000c1100 100015010191001d1101 2001060110a1010e1110 3001170111b1011f1111 Example: eca8 6420 1110 1100 1010 1000 0110 0100 0010 0000

25 COMPUTING SYSTEMS

26 Computing Introduction to Computing Systems What is a computing system?

27 Computing Introduction to Computing Systems What is a computing system? What does it mean to compute something?

28 Chomsky’s Hierarchy What does Noam Chomsky have to do with computation?

29 Chomsky’s Hierarchy What does Noam Chomsky have to do with computation? What do languages have to do with computing?

30 Chomsky’s Hierarchy

31 Finite Automata

32 Pushdown Automata

33 Turing Machine

34 Turing Equivalence What does it take to create a Turing Machine? What does this say about computing systems?

35 Bits, Bytes, and Ints

36 Binary Representations 0.0V 0.5V 2.8V 3.3V 010

37 Encoding Byte Values Byte = 8 bits – Binary 00000000 2 to 11111111 2 – Decimal: 0 10 to 255 10 – Hexadecimal 00 16 to FF 16 Base 16 number representation Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’ Write FA1D37B 16 in C as – 0xFA1D37B – 0xfa1d37b 000000 110001 220010 330011 440100 550101 660110 770111 881000 991001 A101010 B111011 C121100 D131101 E141110 F151111 Hex Decimal Binary

38 Byte-Oriented Memory Organization Programs Refer to Virtual Addresses – Conceptually very large array of bytes – Actually implemented with hierarchy of different memory types – System provides address space private to particular “process” Program being executed Program can clobber its own data, but not that of others Compiler + Run-Time System Control Allocation – Where different program objects should be stored – All allocation within single virtual address space 000 FFF

39 Machine Words Machine Has “Word Size” – Nominal size of integer-valued data Including addresses – Most current machines use 32 bits (4 bytes) words Limits addresses to 4GB Becoming too small for memory-intensive applications – High-end systems use 64 bits (8 bytes) words Potential address space ≈ 1.8 X 10 19 bytes x86-64 machines support 48-bit addresses: 256 Terabytes – Machines support multiple data formats Fractions or multiples of word size Always integral number of bytes

40 Word-Oriented Memory Organization Addresses Specify Byte Locations – Address of first byte in word – Addresses of successive words differ by 4 (32-bit) or 8 (64-bit) 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 32-bit Words BytesAddr. 0012 0013 0014 0015 64-bit Words Addr = ?? Addr = ?? Addr = ?? Addr = ?? Addr = ?? Addr = ?? 0000 0004 0008 0012 0000 0008

41 Data Representations C Data TypeTypical 32-bitIntel IA32x86-64 char111 short222 int444 long448 888 float444 double888 long double810/1210/16 pointer448

42 Byte Ordering How should bytes within a multi-byte word be ordered in memory? Conventions – Big Endian: Sun, PPC Mac, Internet Least significant byte has highest address – Little Endian: x86 Least significant byte has lowest address

43 Byte Ordering Example Big Endian – Least significant byte has highest address Little Endian – Least significant byte has lowest address Example – Variable x has 4-byte representation 0x01234567 – Address given by &x is 0x100 0x1000x1010x1020x103 01234567 0x1000x1010x1020x103 67452301 Big Endian Little Endian 01234567 452301

44 AddressInstruction CodeAssembly Rendition 8048365:5b pop %ebx 8048366:81 c3 ab 12 00 00 add $0x12ab,%ebx 804836c:83 bb 28 00 00 00 00 cmpl $0x0,0x28(%ebx) Reading Byte-Reversed Listings Disassembly – Text representation of binary machine code – Generated by program that reads the machine code Example Fragment Deciphering Numbers – Value: 0x12ab – Pad to 32 bits: 0x000012ab – Split into bytes: 00 00 12 ab – Reverse: ab 12 00 00


Download ppt "Lecture 2: Representing Numbers CS 2011 Fall 2014, Dr. Rozier."

Similar presentations


Ads by Google