Lecture 2: Number Representa2on

Similar documents
Sign & Magnitude vs 2 s Complement ( Signed Integer Representa:ons)

How a computer runs a program. Binary Representa8on and Opera8ons on Binary Data. Opera8ng System 9/17/13. You can view binary file contents

Data Representa+on in Memory

15110 Principles of Computing, Carnegie Mellon University - CORTINA. Digital Data

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

University of California, San Diego CSE 30 Computer Organization and Systems Programming Winter 2014 Midterm Dr. Diba Mirza

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Number System. Introduction. Decimal Numbers

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Bits, Bytes, and Integers

CMPE223/CMSE222 Digital Logic Design. Positional representation

Binary Representations and Arithmetic

Binary Arithme-c CS 64: Computer Organiza-on and Design Logic Lecture #2

Inf2C - Computer Systems Lecture 2 Data Representation

Computer Organization

Chapter 2 Bits, Data Types, and Operations

UNIT IV: DATA PATH DESIGN

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

CS 61C: Great Ideas in Computer Architecture. MIPS Instruc,on Representa,on II. Dan Garcia

Binary Values. CSE 410 Lecture 02

Chapter 2 Bits, Data Types, and Operations

T02 Tutorial Slides for Week 2

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

Number systems & Bit opera1ons. h#p://xkcd.com/99/

World Inside a Computer is Binary

Lecture 3: Instruction Set Architecture

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

MIPS Instruc,ons CS 64: Computer Organiza,on and Design Logic Lecture #8

CS & IT Conversions. Magnitude 10,000 1,

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

CS 61C: Great Ideas in Computer Architecture Func%ons and Numbers

Chapter 2 Bits, Data Types, and Operations

CS 61C: Great Ideas in Computer Architecture Lecture 2: Introduction to C, Part I

Chapter 2 Bits, Data Types, and Operations

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

UNIT 7A Data Representation: Numbers and Text. Digital Data

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Representa7on of integers: unsigned and signed Conversion, cas7ng Expanding, trunca7ng Addi7on, nega7on, mul7plica7on, shiaing

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Floa=ng- Point Numbers

CS 101: Computer Programming and Utilization

Arithmetic Processing

Fundamentals of Programming Session 2

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

FILE IO AND DATA REPRSENTATION. Problem Solving with Computers-I

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Octal and Hexadecimal Integers

Memory Addressing, Binary, and Hexadecimal Review

Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Operations, Operands, and Instructions

Lecture 4 (part 2): Data Transfer Instructions

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Number systems and binary

CS61C : Machine Structures

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

FLIPPED CLASS F#3- Number System. Department of CSE, Coimbatore CTPS 2018

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Unsigned Binary Integers

Unsigned Binary Integers

Chapter 1 Emad Felemban

Chapter 2 Bits, Data Types, and Operations

Arithmetic and Bitwise Operations on Binary Data

BINARY SYSTEM. Binary system is used in digital systems because it is:

M1 Computers and Data

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Octal & Hexadecimal Number Systems. Digital Electronics

Chapter 2 Number System

EE 109 Unit 6 Binary Arithmetic

Writing a Fraction Class

Topic Notes: Bits and Bytes and Numbers

Chapter 10 Binary Arithmetics

The type of all data used in a C++ program must be specified

Bitwise Instructions

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

COMP2121: Microprocessors and Interfacing. Number Systems

Data Representation and Binary Arithmetic. Lecture 2

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems

Integer Representation

CHW 261: Logic Design

Lecture 7: Examples, MARS, Arithmetic

Floa.ng Point : Introduc;on to Computer Systems 4 th Lecture, Sep. 10, Instructors: Randal E. Bryant and David R.

Number Systems and Number Representation

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language. Krste Asanović & Randy Katz

Agenda. CS 61C: Great Ideas in Computer Architecture. Lecture 2: Numbers & C Language 8/29/17. Recap: Binary Number Conversion

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

data within a computer system are stored in one of 2 physical states (hence the use of binary digits)

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

The Design of C: A Rational Reconstruction

Transcription:

CSE 30: Computer Organization and Systems Programming Lecture 2: Number Representa2on Diba Mirza University of California, San Diego 1

Levels of Representation High Level Language Program (e.g., C) Compiler Assembly Language Program (e.g.,arm) Assembler Machine Language Program (ARM) Machine Interpreta4on Hardware Architecture DescripBon (e.g., block diagrams) Architecture Implementa4on temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; ldr r0, [r2] ldr r1, [r2, #4] str r1, [r2] str r0, [r2, #4] 0000 1001 1100 0110 1010 1111 0101 1000 1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111 Logic Circuit DescripBon (Circuit SchemaBc Diagrams) 2 Dan Garcia

Recall the stored program model Q: A key feature of the stored program model is that computa2on is performed A. by an electronic circuit consis2ng of transistors B. on instruc2ons and data that reside in memory C. on instruc2ons that have to necessarily be in binary format D. None of the above 3

Encoding informa2on Encoding numbers (unsigned) using posi%onal encoding Digits Base Example A number, wrioen as the sequence of digits d n d n- 1 d 2 d 1 d 0 in base b represents the value Why is each important?? 4

How many bits are needed to represent A. 6 any hex digit? B. 5 C. 4 D. 3 5

101 5 =? A. 26 B. 51 C. 126 D. 130 6

External vs. Internal Representa2on External representa2on: Convenient for programmer Internal representa2on: Actual representa2on of data in the computer s memory and registers: Always binary (1 s and 0 s) Important to be able to convert between the two 7

Base Conversions You should be able to convert between any two bases Decimal to Binary Decimal to hex Hex to binary 8

Binary to Decimal 1 0 1 1 0 2 =? In decimal 9

Decimal to binary: 34 10 =? 2 A. 10001 B. 10010 C. 10 0010 D. 111110 10

Hex to binary: 2 3 C 16 =? 2 A. 0010 0011 1010 B. 1011 1110 C. 10 0011 1100 D. 1000011011000 11

Hex to binary Each hex digit corresponds directly to four binary digits 35AE 16 = 0011010110101110 2 (3 = 0011, 5 = 0101, A = 1010, E = 1110) 12

Every hex digit corresponds to 4 binary digits, how many binary digits does an octal digit correspond to? A. 2 B. 3 C. 4 D. 5 13

Hexadecimal to decimal 25B 16 =? Decimal 14

Hexadecimal to decimal Use polynomial expansion 25B 16 = 2*256 + 5*16 + 11*1 = 512 + 80 + 11 = 603 15

Decimal to hex: 26 10 =? 16 A. 19 B. 1A C. 1B 16

BIG IDEA: Bits can represent anything!! Numbers Characters Logical values Colors: Memory addresses Instructions Red Green Blue N bits can be used to represent at most 2 N things 17

How We Store Numbers Binary numbers in memory are stored using a finite, fixed number of bits typically: 8 bits (byte) 16 bits (half word) 32 bits (word) 64 bits (double word or quad) If posi2ve pad extra digits with leading 0s A byte represen2ng 4 10 = 00000100 18

A byte can store unsigned values up to A. 127 B. 128 C. 255 D. 256 Generalize to N bits 19

Integer representa2on Think about representa2on and storage together The number of bits available (finite and fixed) determines: the exact representa2on of numbers in memory the range of values that can be correctly represented 20

Unsigned Numbers Some types of numbers, such as memory addresses, will never be nega2ve Some programming languages reflect this with types such as unsigned int, which only hold posi2ve numbers In an unsigned byte, values will range from 0 to 255 21

How to Represent Signed Numbers? Representa2on called sign and magnitude Have a separate bit for sign (Most significant Bit MSB) Set it to 0 for posi2ve, and 1 for nega2ve Wheel of numbers 22

In sign and magnitude, we will be able to represent in one byte A. - 63 to 63 B. - 127 to 127 C. - 128 to 127 D. - 255 to 255 E. 0 to 255 23

Number Representation What do we do with numbers? 24

Shortcomings of sign and magnitude? Arithmetic circuit complicated Special steps depending whether signs are the same or not Also, two zeros 0x00000000 = +0 ten 0x80000000 = 0 ten Therefore sign and magnitude abandoned! 25

One s Complement To make a number nega2ve, just flip all its bits! 26

What is the range of numbers we can represent in One s complement format using N bits A. - 2 N- 1 to 2 N- 1 B. - 2 N- 1 to 2 N- 1-1 C. - (2 N- 1-1) to 2 N- 1-1 D. - 2 N to 2 N 27

Short comings of One s Complement S2ll have two zeros (11111111 and 00000000) Need an extra step in addi2on if there is a carry out see example 1.6 in ARM book 28

Two s Compliment Each two s compliment number is now - 2 n- 1 *d n- 1 +2 n- 2 *d n- 2 + +2 1 *d 1 +2 0 *d 0 29

Two s Complement Flip all the bits of unsigned representa2on and add 1 30

Two s Complement: 1101 2 =? 10 A. - 2 B. - 3 C. - 4 D. - 5 31

Nega2ng Two s Compliment To negate any number, flip all the bits and add 1 32

The nega2on of 11110001 2 is 2 A. 00001110 B. 00001111 C. 00011110 D. 01110001 33

The nega2on of 11110001 2 is 2 A. 00001110 B. 00001111 C. 00011110 D. 01110001 34

Sign Extension 35

Addi2on and Subtrac2on Posi2ve and nega2ve numbers are handled in the same way. The carry out from the most significant bit is ignored. To perform the subtrac2on A - B, compute A + (two's complement of B) 36