198:211 Computer Architecture

Similar documents
Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Number Representation

The string of digits in the binary number system represents the quantity

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

CSI 333 Lecture 1 Number Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Systems I: Computer Organization and Architecture

DNA Data and Program Representation. Alexandre David

2011, The McGraw-Hill Companies, Inc. Chapter 3

Numbering Systems. InThisAppendix...

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Lecture 11: Number Systems

HOMEWORK # 2 SOLUTIO

Lecture 2. Binary and Hexadecimal Numbers

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

The programming language C. sws1 1

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Sources: On the Web: Slides will be available on:

Computer Science 281 Binary and Hexadecimal Review

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Chapter 4: Computer Codes

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Binary Representation

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Binary Numbers. Binary Octal Hexadecimal

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Number Systems. Introduction / Number Systems

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Chapter 7D The Java Virtual Machine

Solution for Homework 2

Base Conversion written by Cathy Saxton

The Answer to the 14 Most Frequently Asked Modbus Questions

Useful Number Systems

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

CPEN Digital Logic Design Binary Systems

Pemrograman Dasar. Basic Elements Of Java

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Binary, Hexadecimal, Octal, and BCD Numbers

Chapter 1: Digital Systems and Binary Numbers

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

How To Write Portable Programs In C

Binary Numbering Systems

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Unsigned Conversions from Decimal or to Decimal and other Number Systems

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Chapter 2. Binary Values and Number Systems

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

CS321. Introduction to Numerical Methods

The use of binary codes to represent characters

Technical Support Bulletin Nr.18 Modbus Tips

NUMBER SYSTEMS. 1.1 Introduction

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Informatica e Sistemi in Tempo Reale

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

ASCII Characters. 146 CHAPTER 3 Information Representation. The sign bit is 1, so the number is negative. Converting to decimal gives

Basic Use of the TI-84 Plus

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

Copyright 2012 Pearson Education, Inc. Chapter 1 INTRODUCTION TO COMPUTING AND ENGINEERING PROBLEM SOLVING

CS201: Architecture and Assembly Language

Counting in base 10, 2 and 16

Positional Numbering System

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

(Refer Slide Time: 00:01:16 min)

3. Convert a number from one number system to another

PFB366 Profibus-DP Gateway User Manual

Chapter 5. Binary, octal and hexadecimal numbers

Data Storage. 1s and 0s

Numerical Matrix Analysis

=

MACHINE INSTRUCTIONS AND PROGRAMS

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Digital Logic Design. Introduction

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

So far we have considered only numeric processing, i.e. processing of numeric data represented

Lecture 8: Binary Multiplication & Division

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Chapter 1. Binary, octal and hexadecimal numbers

ELEG3924 Microprocessor Ch.7 Programming In C

Chapter 5 Instructor's Manual

Decimal to Binary Conversion

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

CHAPTER 5 Round-off errors

Transcription:

198:211 Computer Architecture Topics: Lecture 8 (W5) Fall 2012 Data representation 2.1 and 2.2 of the book Floating point 2.4 of the book 1

Computer Architecture What do computers do? Manipulate stored information Manipulation: operations more on this later Information is data: how is it represented? Basic information: numbers Human beings have represented numbers throughout history Roman numerals Decimal system Discoveregypt.com 2

Number System Comprises of Set of numbers or elements Operations on them (+ - / *) Rules that define properties of operations (identity, inverse ) Need to assign value to numbers Let us take decimal system 1 s place, 10 s place, 100 s place etc Base 10 Value= i 10 i Humans use decimal 3

Binary numbers Base 2; each digit is 0 or 1 Each bit in place i has value 2 i Binary representation is used in computers Easy to represent by switches (on/off) Manipulation by Digital logic in hardware But hard for humans to read (13) 10 = (1101) 2 4

Hexadecimal representation Binary hard to read for humans Especially 16 bits, 32 bits, 64 bits 1010101001010101 Base 16 representation or hex representation Symbols ={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} Value = i 16 i First 10 (0 through 9) symbols are same as decimal numbers A=10,B=11,C=12, D=13, E=14, F=15 5

Decimal to binary main(){ int N,i=0; int Maxbits=32; int bitarray[maxbits]; scanf ( %d, &N): for (i=0;i<maxbits;i++) bitarray[i]=0; /* initialize */ i=0; while (N > 0){ /* MSB is bit 0, LSB is bit 31 */ bitarray[maxbits-1-i]=n%2;i++; /* mod function */ N=N/2; } i=0; for (i=0; i<maxbits; i++) printf( %d,bitarray[i]); } 6

Same for Hex Example: Convert 10 in decimal to binary The code for binary works for any base with modifications For hex, replace by N%16 and N=N/16 replace reminders > 9 by A, B, C, D, E and F Example: Convert 240 to HEX 7

Binary to decimal Convert 110110 to decimal Value = i*2 i Value = 2 5 2 4 2 2 2 1 = 32+ 16 + 4 + 2 = 54 8

Converting Hex to binary Each digit in Hex can be represented by 4 bit binary (base 16) or nibble Convert 2A8C to binary 0010 1010 0100 1100 9

Convert Binary to hex Group binary bits into groups of four Replace each nibble by a hex digit Example 1011011110011100 1011011110011100 B79C or 0x B79C In C, numeric constants starting with 0x are interpreted as being in hexadecimal 10

Examples 0x8F7A93 to binary 1011011110011100 to hex 0xC4E5 to decimal 11

Decimal and binary fractions In decimal, digits to the right of radix point have value 1/10 i for each digit in the i th place 0.25 is 2/10 + 5/100 Similarly, in binary, digits to the right of radix point have value 1/2 i for each i th place after the decimal point. Binary Fractions are the same except the base is different 8.625 is 1000.101 12

Decimal to binary example 0.625 to binary ANS: 0.101 0.625*2 = 1.25 output 1 0.25*2 =0.5 output 0 0.5*2 = 1 output 1 Exit Algorithm /* precondition: 0< number <1) number=decimalfraction while (number >0) { number=number*2 /*shift left */ if (number >=1) {Output result=1; number=number-1} else Output result=0 } 13

Decimal to binary fractions Decimal Binary 0.5 0.1 0.25 0.01 0.625 0.101 0.75 0.11 14

Data sizes All Information is represented in binary form but require different sizes Characters in 1 byte, integers 2 to 4 bytes, real numbers 4 to 8 bytes C declaration 32-bit machine 64-bit machine char 1 1 Short int 2 2 int 4 4 pointer 4 8 float 4 4 double 8 8 15

Big endian vs little endian A binary representation of a number in memory may require multiple bytes How to determine value of a sequence of bytes Most Significant byte first big endian Lease significant byte first little endian Depends on the type of machine Why we need to know: Look at machine code If we are to interpret bytes and determine value One computer (big endian) sending data to another computer (small endian) Need to convert into standard form before transmitting 16

Representing integers Signed integers Unsigned or natural numbers Directly represent as binary What about negative numbers? Signed Magnitude MSB is sign bit S Magnitude 4 is 0100-4 1100 3 is 0011-3 1011 2 is 0010-2 1010 1 is 0001-1 1001 0 is 0000..what is 1000? Problems: two zeros +ve 0 and ve 0 normal bit-wise addition does not work -1 + 4 17

Representing Integers Divide the binary space into two halves One with leading 0s are +ve One with leading 1s are ve This is called two s complement representation Two bit binary numbers 00 01 10 11 0 1-2 -1 Three bit 000 001 010 011 100 101 110 111 0 1 2 3-4 -3-2 -1 18

2s complement advantages Adding two integers works as normal arithmetic Normal arithmetic works for 2 s complement (ignore carry) Only 1 zero X+ (-X) = 0 Used in almost all computers 19

Negate a 2s complement invert the bits and add 1 The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. X = 001 X 110 à 111 All 1s is -1, so add 1 to make it zero So, to get X, invert all bits and add 1 20

Finding 2s complement Take the binary representation and invert all bits Step1: 0 to 1 and 1 to 0 Step 2:Then add 1 Example: 00101 (5) (-5) is Find 2s complement of 9 21

Finding 2s complement Copy all bits from right to left until first 1 Atlantic ocean rule!! At Then flip all bits 0100 1 1011 1 Example find 2s complement of 0100, 0110 0100 0110 22

Decimal value of 2s complement Most significant bit has ve value X n-1, X n-2,.. X 1, X 0 Value of MSB is -2 (n-1) Rest is same as +ve binary number 110011 what is the decimal value? 23

Decimal value of 2 s complement If leading bit or MSB is 1, take 2 s complement to get +ve number Determine decimal value of number And add ve sign to it If leading bit or MSB is 0, compute as normal Example 1100110 TWO 24

1s complement Alternative representation -ve numbers represented by the complement Max numbers that can be represented is halved When adding ve numbers carry need to be added to the result -3 + (-2) 100 101 1 001 à add carry 1 010 à 2 but correct answer is (-)5 Overflow 000 001 010 011 100 101 110 111 0 1 2 3-3 -2-1 -0 101 (-2) 110 (-1) ----- 1011 -------- 1 --------- 100 (-3) 25

ASCII Characters are also stored as bits 1 byte is 8 bits but MSB is used for error detection ASCII represents typical keys on a keyboard 7 bits is 128 different possibilities 7 bit ASCII included printable and nonprintable characters Non-printable for controlling printer such as LF or linefeed 26

ASCII table 27

unicode Extended to 16 bit characters Represent other characters (Japanese) Java supports this format In Unicode, the first 128 characters are ASCII 28

Floating point With integers range is limited short int 2 bytes 2 16 unsigned short int Unsigned: Range is natural number 0 to 65536 Signed: 2s complement is -32768 to 32767 for int (4 bytes) -2147483648 to 2147483647 Can also be represented as magnitude and exponent 2.147483647x10 9 29

Scientific notation 2.147483647x10 9 Mantissa exponent Number of digits in Mantissa à precision Exponent gives range A binary number can also be expressed in this form 10111011 à 1.0111011x2 7 30

Same number with varying exponent 10101 à 21.. In decimal 1010.1 x 2 à 10.5 x 2 101.01 x 2 2 à 5.25 x 4 10.101 x 2 3 à 2.625 x 8 Too many ways to represent the same number Need a standard representation 31

IEEE floating point standard Most computers follow IEEE 754 standard Single precision (32 bits) Double precision (64 bits) Extended precision (80 bits) S Fraction Exponent 32

Floating point in C 32 bits single precision or float 1 sign bit, 23 bits for mantissa, 8 bits for exponent Exponent is power of 2 Signed magnitude Sign bit is 1 for ve numbers, sign bit is 0 for +ve numbers Exponent has 8 bits 0 to 256 or -128 to + 127 2 128 is approx 10 38 Range is -3.4x 10 38 to +3.4x 10 38 For double precision 1 sign bit, 11 bits for exponent, 52 bits for mantissa Range is -1.798x 10 308 to +1.798x 10 308 33

Exponent bias The binary exponent is represented by adding a bias of 127 Saves an extra bit for sign bit Note: it is not 2s complement 2 3 is 2 130 which is 2 10000010 2 0 is 2 127 which is 2 01111111 2-3 is 2 124 which is 2 01111100 34

Normalization The exponent value is adjusted so that the mantissa has a 1 before the radix point 0.25 is 0.01x 2 0 adjusted to 1x 2-2 4.625 is 100.101 x 2 0 adjusted to 1.00101 x2 2 64 is 1000000 x 2 0 adjusted 1x 2 6 In this way, the mantissa always has 1 digit with value 1 This can be omitted to save a bit!!! 35

Decimal to floating point 5.625 In binary 101.101 à 1.01101 x 2 2 Exponent field has value 2 add 127 to get 129 Exponent is 10000001 Mantissa is 01101 Sign bit is 0 0 0110100000000000000000 10000001 36

One more example Convert 12.375 to floating point representation Binary is 1100.011 37

Floating point to decimal 1 10000010 0100100000000000000000 What is the decimal value of the above? Exponent is (10000010) - 127 Mantissa is 1.01001 Sign bit is -1 s f e (1 2s) (1 + f ) 2 e bias 38

Special cases 0 00000000 00000000000000000000000 All zeros 0 (+ 0) 1 00000000 00000000000000000000000 All zeros with sign bit is -0 (-0) 0 11111111 00000000000000000000000 Note: the minimum value in the exponent after adding the bias should be 1. Hence, the minimum value for the exponent in single precision is = -126 (=1-127 or x1-x7f) + Infinity 1 11111111 00000000000000000000000 -Infinity Note: the maximum value in the exponent after adding the bias 254. Hence, the maximum value for the exponent in single precision is = +127 (=254-127 or xfe-x7f) 39

Extended precision 80 bits used to represent a real number 1 sign bit, 15 bit exponent, 64 bit mantissa 20 decimal digits of accuracy 10-4932 to 10 4932 Not supported in C 40