Compsci 210 Tutorial Two CompSci 210 - Semester Two 2016.

Slides:



Advertisements
Similar presentations
DATA REPRESENTATION CONVERSION.
Advertisements

Lecture - 2 Number systems and computer data formats
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 2: Data Representation.
©Brooks/Cole, 2003 Chapter 3 Number Representation.

2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Computer Science 210 Computer Organization Floating Point Representation.
Simple Data Type Representation and conversion of numbers
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
IT253: Computer Organization
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles of Computer.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
COMPSCI 210 Semester Tutorial 1
Number Systems Spring Semester 2013Programming and Data Structure1.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Data Representation, Number Systems and Base Conversions
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 2: Number Systems & x86 Instructions Constantine D. Polychronopoulos Professor, ECE Office: 463.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale Floating point arithmetic.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
Dr. Clincy Slide 1 CS Chapter 2 (Part 1 of 3) Dr. Clincy Professor of CS Ch 2 Appendix pages will not be on the exam – already covered this.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Computer Representation of Information
William Stallings Computer Organization and Architecture 8th Edition
MATH Lesson 2 Binary arithmetic.
Floating Point Representations
CS2100 Computer Organisation
Department of Computer Science Georgia State University
Data Representation COE 308 Computer Architecture
Programming and Data Structure
Computer Science 210 Computer Organization
NUMBER SYSTEMS.
Data Representation ICS 233
Data Representation.
Number Representation
Number Representation
Data Representation Binary Numbers Binary Addition
Floating Point Math & Representation
Dr. Clincy Professor of CS
Chapter 3 Data Storage.
CS 232: Computer Architecture II
Number System conversions
Number Systems.
William Stallings Computer Organization and Architecture 7th Edition
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Scientific Notation Scientific notation takes the form: M x 10n
Data Representation COE 301 Computer Organization
Number Representations
Data Representation Data Types Complements Fixed Point Representation
Dr. Clincy Professor of CS
ECEG-3202 Computer Architecture and Organization
Number Representation
Storing Negative Integers
How Computers Store Data
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Data Representation ICS 233
OBJECTIVES After reading this chapter, the reader should be able to :
Number Representations
Data Representation COE 308 Computer Architecture
Presentation transcript:

Compsci 210 Tutorial Two CompSci 210 - Semester Two 2016

Tutorials Tutorials are not compulsory but are strongly recommended. Tutorials try to enhance your understanding of content from lecture and apply the content based on examples and exercises. Tutorials only cover the content from the lecture. Please feel free to contact us if you have any problem. Tutorials materials can be found at Canvas: https://canvas.auckland.ac.nz/courses/1193/files/

Tutors https://canvas.auckland.ac.nz/courses/1193/assignments/syllabus  Josh Hill      jhil955@cs.auckland.ac.nz      Room: 303.461 - 4th Floor Lunch Area Computer Science Building      Office hours: Monday 12 - 1 & Wednesday 11 - 12  Ben Wang      ywan769@aucklanduni.ac.nz      Room: 303.461 - Research Room, the corner of 4th Floor, Computer Science Building      Office hours: Tuesday 2 - 3 & Thursday 12 - 1

Agenda Quick review last tutorial Binary-decimal conversion - easy Conversion Between Hex and Binary – easy Float point – intermediate (just mention a little today)

value1 ∗ 𝑠𝑐𝑎𝑙𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛1 * + value2 * 𝑠𝑐𝑎𝑙𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛2 + … decimal and binary value1 ∗ 𝑠𝑐𝑎𝑙𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛1 * + value2 * 𝑠𝑐𝑎𝑙𝑒 𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛2 + … The decimal number “210” 2 ∗ 10 2 +1∗ 10 1 +0∗ 10 0 = 210 the binary number “101” 1∗ 2 2 +0∗ 2 1 +1∗ 2 0 =5

Calculate negative number Most Significant(MS) bit is sign bit Range of an n-bit number: - 2 𝑛−1 through 2 𝑛−1 – 1 Keep negative zero in your mind

Calculate negative number the 2’s complement number “10001101” This number is negative, because the leftmost bit is 1 The complement of the other bits is, 0001101 →1110010+1=1110011 “1110011” represents a regular binary number, so, 1⋅64+1⋅32+1⋅16+0⋅8+0⋅4+1⋅2+1⋅1=115 Remember: The number is negative, so the final value is, −115

Decimal to Binary Conversion(1)

Decimal to Binary Conversion(2) CompSci 210 - Semester One 2016

Exercise 1.2 Convert the following decimal numbers into 8-bit 2’s complement binary numbers 𝟏𝟎𝟐 64 33 −125 127

SOLUTION 1.2.A Decimal Value: 102 102 / 2 = 51 R 0 51 / 2 = 25 R 1 25 / 2 = 12 R 1 12 / 2 = 6 R 0 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 0 / 2 = 0 R 0

SOLUTION 1.2.A Decimal Value: 102 102 / 2 = 51 R 0 51 / 2 = 25 R 1 25 / 2 = 12 R 1 12 / 2 = 6 R 0 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 0 / 2 = 0 R 0 0 1 1 0 0 1 1 0 Answer: 01100110

SOLUTION 1.2.D Decimal Value: -125 125 / 2 = 62 R 1 62 / 2 = 31 R 0 31 / 2 = 15 R 1 15 / 2 = 7 R 1 7 / 2 = 3 R 1 3 / 2 = 1 R 1 1 / 2 = 0 R 1 0 / 2 = 0 R 0

SOLUTION 1.2.D Decimal Value: -125 125 / 2 = 62 R 1 62 / 2 = 31 R 0 31 / 2 = 15 R 1 15 / 2 = 7 R 1 7 / 2 = 3 R 1 3 / 2 = 1 R 1 1 / 2 = 0 R 1 0 / 2 = 0 R 0 0 1 1 1 1 1 0 1 Calculate 2’s complement: 01111101→10000010+1 Answer: 10000011

Exercise 1.2 Solutions 102 64 33 −125 127 Now we’ll solve them all using the process from the previous slides

Exercise 1.2 Solutions 102 2 =51r0 0 64 2 =32r0 0 33 2 =16r1 1 Step 1: Divide by 2 and write down the remainder to the side

Exercise 1.2 Solutions 51 2 =25r1 10 32 2 =16r0 00 16 2 =8r0 01 Step 2: Divide again and write the new remainder to the left

Exercise 1.2 Solutions 25 2 =12r1 110 16 2 =8r0 000 8 2 =4r0 001 Step 3: Repeat CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 12 2 =6r0 0110 8 2 =4r0 0000 4 2 =2r0 0001 Step 3: Repeat CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 6 2 =3r0 00110 4 2 =2r0 00000 2 2 =1r0 00001 Step 3: Repeat CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 3 2 =1r1 100110 2 2 =1r0 000000 1 2 =0r1 100001 Step 3: Repeat CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 1 2 =0r1 1100110 1 2 =0r1 1000000 Step 3: Repeat CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 0 2 =0r0 01100110 0 2 =0r0 01000000 Step 3: Repeat. When the quotient and remainder are both zero, stop. CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 0 2 =0r0 01100110 0 2 =0r0 01000000 Step 4: Take the 2’s complement of any negative numbers CompSci 210 - Semester One 2016

Exercise 1.2 Solutions 102 = 01100110 64 = 01000000 33 = 00100001 102 = 01100110 64 = 01000000 33 = 00100001 -125 = 10000011 127 = 01111111 Done CompSci 210 - Semester One 2016

Conversion Between Hex and Binary Converting between hexadecimal and binary is easy! Recall that hexadecimal uses the normal digits 0-9, plus the letters A-F to represent the values 10-15. 0 1 2 3 4 5 6 7 8 9 A B C D E F position is expensive for human being (read/write/check) But sometime we want to express these machine level number directly (eg. memory address, Mac address, color code) CompSci 210 - Semester One 2016

Conversion Between Hex and Binary Every hexadecimal digit can be converted into a 4 digit binary number. Examples: 0 16 = (0000) 2 3 16 = (0011) 2 8 16 = (1000) 2 B 16 = (1011) 2 F 16 = (1111) 2 CompSci 210 - Semester One 2016

Exercise 1.3 Convert the following 2’s complement binary numbers to hexadecimal 010 10011011 0101110100010100 1111111101010001 CompSci 210 - Semester One 2016

Solution 1.3.c 0101110100010100 Split the number into groups of four, starting on the right 0101 1101 0001 0100 Calculate the hexadecimal value for each group 5 D 1 4 Write the solution with the correct sign 0x5D14 (‘0x’ is often used to indicate a hex value) CompSci 210 - Semester One 2016

Exercise 1.3 Solutions 010 10011011 0101110100010100 1111111101010001 Now we’ll solve them all using the process from the previous slides CompSci 210 - Semester One 2016

Exercise 1.3 Solutions 010 1001 1011 0101 1101 0001 0100 1111 1111 0101 0001 Step 1: Split into groups of 4, starting from the right CompSci 210 - Semester One 2016

Exercise 1.3 Solutions 0010 1001 1011 0101 1101 0001 0100 1111 1111 0101 0001 Step 2: Pad the leftmost group with zeros if needed CompSci 210 - Semester One 2016

Exercise 1.3 Solutions 2 9 B 5 D 1 4 F F 5 1 Step 3: Convert each group to hex CompSci 210 - Semester One 2016

Exercise 1.3 Solutions 0x2 0x9B 0x5D14 0xFF51 Step 4: final answer CompSci 210 - Semester One 2016

Exercise 1.4 Convert the following hexadecimal numbers to binary 0xD 0xFE7F CompSci 210 - Semester One 2016

Exercise 1.4 Solutions 0xD 0x6E 0x8001 0xFE7F CompSci 210 - Semester One 2016

Exercise 1.4 Solutions D 6 E 8 0 0 1 F E 7 F Step 1: Split up the hex digits CompSci 210 - Semester One 2016

Exercise 1.4 Solutions 1101 0110 1110 1000 0000 0000 0001 1111 1110 0111 1111 Step 2: Convert the hex digits into 4 digit binary values CompSci 210 - Semester One 2016

Bits and bytes Bits = positions of binary What is byte? Why 8 bits? byte (/ˈbaɪt/) is a unit of digital information that most commonly consists of 8 bits Why 8 bits? powers of 2 are magic How many keys are on a typewriter keyboard include shift? ASCII defined a 7-bit character set. And one extra bit that has been used for all sorts of things One byte is enough for most common characters.

text

ASCII Codes ASCII stands for American Standard Code For Information Interchange. Each key on the keyboard is identified by its unique ASCII code When you type a key on the keyboard, the corresponding eight-bit code is stored and made available to the computer Most keys are associated with more than one code, for example, h and H have two different codes Google search “ASCII Table” and look at the image results for quick reference CompSci 210 - Semester One 2016

Why float point is important The basic idea: can we change the position without changing the value? scientific notation: 975.25 => 9.7525 x 10 2 F ∙10 𝐸 (decimal) F ∙2 𝐸 (binary) F is the float point number

Significant figures

Float point Decimal float point ∙∙∙ 10 3 + 10 2 + 10 1 + 10 0 . (𝐷𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑜𝑖𝑛𝑡) + 10 −1 + 10 −2 + 10 −3 ∙∙∙ ∙∙∙ 1000 + 100 + 10 + 1 . (𝐷𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑜𝑖𝑛𝑡) 𝟏 𝟏𝟎 + 𝟏 𝟏𝟎𝟎 + 𝟏 𝟏𝟎𝟎𝟎 Binary float point ∙∙∙ 2 3 + 2 2 + 2 1 + 2 0 . (𝑏𝑖𝑛𝑎𝑟𝑦 𝑝𝑜𝑖𝑛𝑡) + 2 −1 + 2 −2 + 2 −3 ∙∙∙ ∙∙∙ 8 + 4 + 2 + 1 . (𝑏𝑖𝑛𝑎𝑟𝑦 𝑝𝑜𝑖𝑛𝑡) 𝟏 𝟐 + 𝟏 𝟒 + 𝟏 𝟖

IEEE 754 Floating Point (32-bit) 00000000000000000000000000000000

IEEE 754 Floating Point (32-bit) Sign Bit Fraction (significand) 0 00000000 00000000000000000000000 Exponent Exponent for range; Fraction for accuracy

IEEE 754 Floating Point (32-bit) 00000000 Exponent Unsigned, but biased by 127 Special cases override fraction value 00000000 = 0 11111111 = infinity Example: 10100000 Calculate binary value 10100000= 2 7 + 2 5 =128+32=160 Apply bias 160−127=33

IEEE 754 Floating Point (32-bit) 00000000000000000000000 Fraction 23-bits Represents the fractional part of a number between 1 and 2 (Implied 1 in front) Example: 10100000000000010000001 Prepend a binary point .10100000000000010000001 Add 1 1.10100000000000010000001 CompSci 210 - Semester One 2016

IEEE 754 Floating Point (32-bit) 1100000010100000000000000000000 = -5.0

Exercise 1.5 Convert − 112.0625 10 to IEEE single-precision floating point Convert 01000010001010100000000000000000 𝐼𝐸𝐸𝐸 to decimal CompSci 210 - Semester One 2016

Exercise 1.5.a solution − 112.0625 10 Convert to binary (see next slide) 112.0625 10 = 1110000.0001 2 Move decimal point to compute exponent and fraction 1110000.0001 2 =1.1100000001⋅ 2 6 Add bias to exponent; convert to binary 6+127= 133 10 = 10000101 2 Assemble components 11000010111000000010000000000000 CompSci 210 - Semester One 2016

Converting fractional numbers Decimal Value: 112 112 / 2 = 56 R 0 56 / 2 = 28 R 0 28 / 2 = 14 R 0 14 / 2 = 7 R 0 7 / 2 = 3 R 1 3 / 2 = 1 R 1 1 / 2 = 0 R 1 0 / 2 = 0 R 0 Decimal Value: .0625 0.0625 * 2 = 0 .125 0.125 * 2 = 0 .25 0.25 * 2 = 0 .5 0.5 * 2 = 1 .0 0 * 2 = 0 112.0625 10 = 1110000.0001 2 CompSci 210 - Semester One 2016

Exercise 1.5.B solution 01000010001010100000000000000000 𝐼𝐸𝐸𝐸 Calculate biased exponent 10000100 2 = 2 7 + 2 2 =128+4=132 Subtract bias from value 132−127=5 Place 1 in front of the fraction and multiply by the exponent value 1.010101⋅ 2 5 =101010.1 convert to decimal 101010.1= 2 5 + 2 3 + 2 1 + 2 −1 =42.5 CompSci 210 - Semester One 2016