ECE260: Fundamentals of Computer Engineering

Similar documents
Four Important Number Systems

Week No. 06: Numbering Systems

Complement Arithmetic

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

CHAPTER 2 NUMBER SYSTEMS

ECE 372 Microcontroller Design

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

Conversions between Decimal and Binary

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Number Representation and Waveform Quantization

Representing signed numbers in Two s Complement notation

CSE 1400 Applied Discrete Mathematics Definitions

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Chapter 1 CSCI

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

0,..., r 1 = digits in radix r number system, that is 0 d i r 1 where m i n 1

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

ECE380 Digital Logic. Positional representation

NUMBERS AND CODES CHAPTER Numbers

Digital Circuits, Binary Numbering, and Logic Gates Cornerstone Electronics Technology and Robotics II

Design of Sequential Circuits

Binary addition example worked out

CSE 241 Digital Systems Spring 2013

Ex code

Multiplication of signed-operands

hexadecimal-to-decimal conversion

CMP 334: Seventh Class

CPE100: Digital Logic Design I

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

Digital Systems and Information Part II

Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices. Integers & Algorithms (2.5)

0 / 1 Now, Binary value of the given number :-

LOGIC CIRCUITS. Basic Experiment and Design of Electronics

Chapter 9 - Number Systems

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

LOGIC CIRCUITS. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

Numbers and Arithmetic

ALU (3) - Division Algorithms

CSCI 255. S i g n e d N u m s / S h i f t i n g / A r i t h m e t i c O p s.

JNTU World. Digital Logic Design. Introduction

Numbers and Arithmetic

ENGIN 112 Intro to Electrical and Computer Engineering

LABORATORY MANUAL MICROPROCESSOR AND MICROCONTROLLER

Notes for Chapter 1 of. Scientific Computing with Case Studies

12/31/2010. Digital Operations and Computations Course Notes. 01-Number Systems Text: Unit 1. Overview. What is a Digital System?


Numbers & Arithmetic. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See: P&H Chapter , 3.2, C.5 C.

Homework 2 Foundations of Computational Math 1 Fall 2018

convert a two s complement number back into a recognizable magnitude.

Arithmetic and Error. How does error arise? How does error arise? Notes for Part 1 of CMSC 460

DSP Design Lecture 2. Fredrik Edman.

THE LOGIC OF COMPOUND STATEMENTS

Chapter 1. Binary Systems 1-1. Outline. ! Introductions. ! Number Base Conversions. ! Binary Arithmetic. ! Binary Codes. ! Binary Elements 1-2

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

17.1 Binary Codes Normal numbers we use are in base 10, which are called decimal numbers. Each digit can be 10 possible numbers: 0, 1, 2, 9.

Combinational Logic Design Arithmetic Functions and Circuits

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

A crash course in Digital Logic

EECS150 - Digital Design Lecture 24 - Arithmetic Blocks, Part 2 + Shifters

Number Representations

ww.padasalai.net

ECE 545 Digital System Design with VHDL Lecture 1. Digital Logic Refresher Part A Combinational Logic Building Blocks

Chapter 4 Number Representations

2.5 정수와알고리즘 (Integers and Algorithms)

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

8/13/16. Data analysis and modeling: the tools of the trade. Ø Set of numbers. Ø Binary representation of numbers. Ø Floating points.

What is Binary? Digital Systems and Information Representation. An Example. Physical Representation. Boolean Algebra

9. Datapath Design. Jacob Abraham. Department of Electrical and Computer Engineering The University of Texas at Austin VLSI Design Fall 2017

Part I, Number Systems. CS131 Mathematics for Computer Scientists II Note 1 INTEGERS

DE58/DC58 LOGIC DESIGN DEC 2014

Base-b representations of integers. (b 진법표현 ) Algorithms for computer arithmetic: Euclidean algorithm for finding GCD s.

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

Lecture 8: Sequential Multipliers

of Digital Electronics

ECE/CS 250 Computer Architecture

Save from: cs. Logic design 1 st Class أستاذ المادة: د. عماد

ECE 250 / CPS 250 Computer Architecture. Basics of Logic Design Boolean Algebra, Logic Gates

ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H Lipasti. Fall 2010 University i of Wisconsin-Madison

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

Lecture 2 Review on Digital Logic (Part 1)

Mark Redekopp, All rights reserved. Lecture 1 Slides. Intro Number Systems Logic Functions

Department of Electrical & Electronics EE-333 DIGITAL SYSTEMS

Logic Theory in Designing of Digital Circuit & Microprocessor

CSEN102 Introduction to Computer Science

COMP 120. For any doubts in the following, contact Agam, Room. 023

Number Theory: Representations of Integers

Base Number Systems. Honors Precalculus Mr. Velazquez

Digital Logic and Design (Course Code: EE222) Lecture 1 5: Digital Electronics Fundamentals. Evolution of Electronic Devices

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

Hardware Design I Chap. 4 Representative combinational logic

Next, we include the several conversion from type to type.

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6201 DIGITAL PRINCIPLES AND SYSTEM DESIGN

Computer arithmetic. Intensive Computation. Annalisa Massini 2017/2018

ECE 545 Digital System Design with VHDL Lecture 1A. Digital Logic Refresher Part A Combinational Logic Building Blocks

Transcription:

Data Representation & 2 s Complement James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy

Data Representation Internally, computers represent all data as binary Provides a simple method to design and build hardware A switch (i.e. a transistor) is either on or off A wire is either charged or not charged All information is encoded as 1 s and 0 s Characters Integers (positive and negative numbers) Non-integers (fixed-point and floating point numbers) Standards ensure interoperability between computers 2 s Complement, ASCII, Unicode, IEEE Floating Point 2

American Standard Code for Information Interchange (ASCII) Common character encoding standard Available in 7-bit and extended 8-bit 7-bit version encodes 2 7 (128) characters 8-bit version encodes 2 8 (256) characters Not so great for languages based on non- English alphabets Unicode has replaced ASCII in many contexts Backwards compatible with ASCII Supports a much wider range of characters 智ボ 3

Encoding Numbers Numbers can be represented in any base Humans typically use base 10 (decimal) so we can count on our fingers Programmers often represent data in base 16 (hexadecimal) Computers represent all data using base 2 (binary) In any base, the decimal value of the i th digit d can calculated as: d Base i base 10 base 2 5 3 8 = 538 ten 1 0 1 1 = 11 ten 2 1 0 digit index 3 2 1 0 digit index (5 10 2 ) + (3 10 1 ) + (8 10 0 ) (5 100) + (3 10) + (8 1) 500 + 30 + 8 (1 2 3 ) + (0 2 2 ) + (1 2 1 ) + (1 2 0 ) (1 8) + (0 4) + (1 2) + (1 1) 8 + 0 + 2 + 1 4

Unsigned Integers Represented as binary value (a bit string) Leftmost bit is called the most significant bit (MSB) Rightmost bit is called the least significant bit (LSB) MSB LSB 32-bit Unsigned Integer digit 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 index 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 The number of bits is determined by the bitness of the computer architecture A 32-bit computer can represent unsigned integers from 0 to 2 32-1 0 to 4,294,967,295 (4.29 Billion) A 64-bit computer can represent unsigned integers from 0 to 2 64-1 0 to 18,446,744,073,709,551,615 (18.4 Quintillion) % 5

Arithmetic Limitations & Overflow The largest unsigned value a 32-bit computer can represent is 4,294,967,295 What happens when user requests 4,294,967,295 + 1? index 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OVERFLOW CPUs have a special status register with an overflow flag to indicate when this happens 6

2 s Complement Signed Integers Must be able to represent both positive AND negative numbers Represented as binary value where the MSB is now a sign bit When sign bit is 1, the signed integer is a negative number When sign bit is 0, the signed integer is a positive number MSB / Sign Bit 32-bit Signed Integer digit 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 index 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 LSB Maximum value less than that of unsigned integers since 1 bit is being used to represent the sign A 32-bit computer can represent signed integers from 2 31 to 2 31-1 2,147,483,648 to 2,147,483,647 7

2 s Complement Signed Integer Examples Positive Number Examples 2,147,483,647 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 247 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Negative Number Examples -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1-2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0-3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 2,147,483,648 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8

Arithmetic Overflow with Signed Integers The largest signed value a 32-bit computer can represent is 2,147,483,647 What happens when user requests 2,147,483,647 + 1? index 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OVERFLOWS 2,147,483,647 + 1 = 2,147,483,648 Similar badness happens if you subtract 1 from 2,147,483,648 9

Binary to Decimal Conversion for Signed Integers Similar to conversion with unsigned integers, but sign bit is multiplied by 2 31 instead of 2 31 If the signed integer is positive => (0 2 31 ) = 0 If the signed integer is negative => (1 2 31 ) = 2,147,483,648 MSB / Sign Bit LSB 32-bit Signed Integer digit 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 index 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 (1 2 31 ) + + (1 2 5 ) + (0 2 4 ) + (1 2 3 ) + (1 2 2 ) + (0 2 1 ) + (1 2 0 ) + + (1 32) + (0 16) + (1 8) + (1 4) + (0 2) + (1 1) 2,147,483,648 + 0 + 32 + 0 + 8 + 4 + 0 + 1 = 2,147,483,603 10

Negating 2 s Complement Signed Integers Step #1: Toggle every bit, including the sign bit (i.e. all 1 s become 0 s and all 0 s become 1 s) Step #2: Add 1 to result of step #1 Example: Negate the integer +2 2 ten 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 First, toggle every bit 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 Then, Add 1 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 = 2 ten 11

Sign Extension for 2 s Complement Signed Integers Used when increasing the number of bits used to represent a signed integer Must extend sign bit to preserve the numeric value (i.e. fill all leading zeros with sign bit) Example: Loading a signed 8-bit value into a 32-bit register If bits [31:9] of register are left as 0 s then sign of 8-bit value may be lost Signed 8-bit value holds 2 ten 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 without sign extension 32-bit register holds value 254 ten 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 WITH sign extension 32-bit register holds correct value 2 ten 12