Level ISA3: Information Representation

Similar documents
Number System. Introduction. Decimal Numbers

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

CS & IT Conversions. Magnitude 10,000 1,

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Number representations

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

COMP Overview of Tutorial #2

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

CHW 261: Logic Design

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

MACHINE LEVEL REPRESENTATION OF DATA

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

Chapter 2: Number Systems

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Chapter 2 Binary Values and Number Systems

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Digital Logic Lecture 2 Number Systems

Lecture 2: Number Systems

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Lecture (01) Introduction Number Systems and Conversion (1)

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Octal and Hexadecimal Integers

CMPE223/CMSE222 Digital Logic Design. Positional representation

Number Systems. Both numbers are positive

T02 Tutorial Slides for Week 2

Chapter 2. Data Representation in Computer Systems

CHAPTER 2 Number Systems

in this web service Cambridge University Press

Electronic Data and Instructions

Module 2: Computer Arithmetic

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

TOPIC: NUMBER SYSTEMS

Digital Systems COE 202. Digital Logic Design. Dr. Muhamed Mudawar King Fahd University of Petroleum and Minerals

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

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

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

What Is It? Instruction Register Address Register Data Register

Digital Fundamentals

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Fundamentals of Programming (C)

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

MC1601 Computer Organization

Octal & Hexadecimal Number Systems. Digital Electronics

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Divide: Paper & Pencil

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

Chapter 1 Emad Felemban

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 01, SPRING 2013

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

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

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

QUIZ: Generations of computer technology. Hardware:

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Introduction to Numbering Systems

Chapter 2 Number Systems and Codes Dr. Xu

Final Labs and Tutors

Number Systems CHAPTER Positional Number Systems

EE292: Fundamentals of ECE

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

Digital Systems and Binary Numbers

Beyond Base 10: Non-decimal Based Number Systems

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

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

CHAPTER 2 (b) : AND CODES

Signed Binary Numbers

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Chapter 1 Preliminaries

Jones & Bartlett Learning, LLC NOT FOR SALE OR DISTRIBUTION. Data Representation in Computer Systems

Switching Circuits and Logic Design Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Number Systems Base r

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

Computer Arithmetic. In this article we look at the way in which numbers are represented in binary form and manipulated in a computer.

Information Science 1

Objectives. Connecting with Computer Science 2

Digital Systems and Binary Numbers

The. Binary. Number System

Digital Systems and Binary Numbers

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

COMP2121: Microprocessors and Interfacing. Number Systems

World Inside a Computer is Binary

Fundamentals of Programming Session 2

Lesson Plan. Preparation

Decimal/Binary Conversion on the Soroban

umber Systems bit nibble byte word binary decimal

DIGITAL SYSTEM DESIGN

Korea University of Technology and Education

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,...

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

Positional Number System

Beyond Base 10: Non-decimal Based Number Systems

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

Internal Data Representation

Transcription:

Level ISA3: Information Representation 1

Information as electrical current At the lowest level, each storage unit in a computer s memory is equipped to contain either a high or low voltage signal Each storage unit exists, therefore, in one of two states, each of which is discrete Since two values are possible, and these values are usually represented by numeric values, we refer to the storage units as binary digits, abbreviated bits 2

Memory cells & data storage Computer memory is organized into groups of bits called cells The number of bits in a cell may vary across hardware platforms, although the 8-bit byte is the most common All data and instructions must be represented in binary form in order to be stored in a computer s memory 3

Integer storage The simplest code for integer storage is unsigned binary form Binary is to base 2 as decimal is to base 10 The binary system is similar to the decimal system, in that it uses positional notation to represent the magnitude of a number In decimal, each digit s position represents a power of 10; in binary, each position is a power of 2 Any value can be used as the base number for integer representation; the next slide illustrates this 4

Equivalent values in different bases Decimal Value Binary Value Base 4 Base 6 Base 8 (Octal) 0 0 0 0 0 1 1 1 1 1 2 10 2 2 2 3 11 3 3 3 4 100 10 4 4 5 101 11 5 5 6 110 12 10 6 7 111 13 11 7 8 1000 20 12 10 9 1001 21 13 11 10 1010 22 14 12 16 10000 100 24 20 32 100000 200 52 40 64 1000000 1000 144 100 128 10000000 2000 332 200 5

Hexadecimal numbers Numeric representation with a base number (called the radix) greater than 10 is also possible Of particular interest in computer systems is radix 16, or hexadecimal numbers As with other bases, base 16 numbers use positional notation Each position represents a power of 16 The symbols employed include the digits 0.. 9 and the letters A (for decimal value 10) through F (decimal 15) 6

Hexadecimal / Decimal Equivalence 7

Hexadecimal / Binary Equivalence Hexadecimal numbers provide convenient abbreviations for equivalent binary values Each hex digit represents 4 binary digits Octal numbers can also be used to abbreviate binary (with 1 octal digit representing 3 bits) but hex is far more common in modern computer systems 8

Converting from one base to another The next several slides describe different methods by which to convert from one base to another It is especially useful to be able to convert back and forth between binary, decimal and hexadecimal notations 9

Converting from any base to decimal The value of a number in any base is the sum of the values of each digit multiplied by successive powers of the base, we can easily convert a number from any other base to decimal if we know the powers of the base The rightmost digit will always be multiplied by 1, since any number to the 0 power is 1 For a 5-digit number with base n, for example, its decimal equivalent would be: digit1 x n 4 + digit2 x n 3 + digit3 x n 2 + digit4 x n + digit5 10

Positional notation 11101 base 10 = 1 x 10000 + 1 x 1000 + 1 x 100 + 0 x 10 + 1 x 1 11101 base 2 = 1 x 16 + 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1 (29 10 ) 11101 base 4 = 1 x 256 + 1 x 64 + 1 x 16 + 0 x 4 + 1 x 1 (337 10 ) 11101 base 6 = 1 x 1296 + 1 x 216 + 1 x 36 + 0 x 6 + 1 x 1 (1549 10 ) 11101 base 8 = 1 x 4096 + 1 x 512 + 1 x 64 + 0 x 8 + 1 x 1 (4673 10 ) 11

Converting from hex to decimal You can use positional notation when converting from hex to decimal as well, but you need to remember to use the decimal values of the digits beyond 9 (A=10, B=11, C=12, D=13, E=14, F=15), multiplying the digit s value by the power of 16 indicated by the digit s position 12

Example The decimal value of F78EC2 is: 15 x 16 5 + (15,728,640) 7 x 16 4 + (458,752) 8 x 16 3 + (32,768) 14 x 16 2 + (3,584) 12 x 16 + (192) 2 (2) ---------------------------------------- 16,223,938 10 13

Division algorithm for converting decimal value n to base b Divide n by b, obtaining quotient & remainder: n = bq 0 + r 0 where 0 <= r 0 < b remainder (r 0 ) is rightmost digit in base b expansion Divide q 0 by b, obtaining: q 0 = bq 1 + r 1 (0 <= r 1 < b) r 1 is second digit from right in base b expansion Continue successive divisions until we obtain a q = 0 14

Example Find octal (base 8) expansion of 4745 10 4745 = 8 * 593 + 1 (rightmost digit) 593 = 8 * 74 + 1 74 = 8 * 9 + 2 9 = 8 * 1 + 1 1 = 8 * 0 + 1 (leftmost digit) Result is 11211 8 15

C++ for base expansion algorithm (for base <= 10) int baseexpand(int n, int b) { int k = 0, digit, expansion = 0; while (n!= 0) { digit = n % b; n = n / b; expansion = expansion + digit * pow(10,k); k++; } } return expansion; 16

Converting binary to hex The easiest way to convert binary numbers to hex involves memorizing the table of equivalence given in slide 8 An awareness of the hex/binary equivalence will also help keep you mindful of the equivalent decimal values for both bases If you know the equivalences, it is easy to apply the conversion method given on the next slide 17

Converting binary to hex (and viceversa) Break the binary expansion into four digit groupings (hextets), starting from the right; expand the leftmost hextet with leading 0s, if necessary Substitute the hexadecimal digit corresponding to each hextet The reverse is also easy; simply convert each hex digit into its equivalent 4-bit group to convert from hex to binary 18

Examples Convert binary value 1001000011101111011 to its hex equivalent: Breaking the expansion into groups of 4 digits, we have: 0100 1000 0111 0111 1011 or: 4 8 7 7 B Convert hexadecimal value 92AF to its binary equivalent: 9 = 1001 2 = 0010 A = 1010 F = 1111 Value is 1001 0010 1010 1111 19

Another method for converting binary to decimal The fastest way to convert binary to decimal is a method called double-dabble (or sometimes double-dibble) This method uses the idea that a subsequent power of 2 is double the previous power of 2 in a binary number Starting with the leftmost bit and working to the right: Double the first bit and add it to the second Double the sum and add it to the next bit Repeat for each bit until the rightmost bit is used 20

Convert 10010011 2 to decimal Step 1: write the binary expansion, leaving spaces between digits: 1 0 0 1 0 0 1 1 Step 2: double the high-order bit and copy it under the next bit: 1 0 0 1 0 0 1 1 x2 ---- 2 Step 3: Add the next bit and double the sum; copy result under next bit: 1 0 0 1 0 0 1 1 2 +0 ----- 2 x2 x2 ----- ----- 2 4 Step 4: Repeat step 3 until you run out of bits (see next slide) 21

Double-dabble conversion of binary to decimal (result) Original value: 1 0 0 1 0 0 1 1 2 4 8 18 36 72 146 + 0 + 0 +1 +0 +0 +1 + 1 ----- ----- ----- ----- ----- ----- ----- 2 4 9 18 36 73 147 x2 x2 x2 x2 x2 x2 x2 ----- ----- ----- ----- ----- ----- ----- 2 4 8 18 36 72 146 Final result 22

Hex to decimal conversion You can combine hex to binary and doubledabble to do hexadecimal to decimal conversion For example, to convert 02CA 16 to decimal: Convert hex to binary by grouping into hextets: 0000 0010 1100 1010 Apply double-dabble method on the binary form 23

Converting fractions Fractions in any base system can be approximated in any other base system using negative powers of the radix (a radix point separates the whole part of a number from its fractional part; for decimal numbers, we call this a decimal point) One of the previous algorithms for conversion of whole numbers used division with remainder to find the digits of the converted base expansion; a similar method for converting fractional numbers uses multiplication by the radix, with the whole part of each product becoming a digit of the result 24

Convert 0.4304 10 to base 5:.4304 x 5 -------- 2.1520 first digit is 2; use fractional part for next calculation.1520 x 5 -------- 0.7600 second digit is 0; continuing.7600 x 5 -------- 3.8000 third digit is 3; continuing.8000 x 5 -------- 4.0000 fourth digit is 4, and fractional part is now 0; done Base 5 equivalent of is.2034 25

Notes on fractional conversion Things don t always work out as neatly as in the previous example For example, we might end up with repeating fractions, or we may simply run into a hard limit on the number of digits that can be stored Most computer systems implement specialized rounding algorithms to provide a predictable degree of accuracy 26

Addition with unsigned binary numbers The rules for adding bits are: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 In the last instance, the result is a place-holder with a carry bit; if two numbers add up to a sum greater than 1, you must carry a 1 to the next column 27

Example Calculate the sum of 1011 2 and 0010 2 : 1011 + 0010 --------- 1 (no carry) 0 (carry the 1) 1 (0 + 0 + 1, no carry) 1 (no carry) --------- 1101 (result) 28

The Carry Bit Every computer system has a hard limit on the amount of memory used to represent a binary integer When two numbers are added, even if each of their values fits within this limit, the value of the sum may be too large to fit into the available space To flag this possibility, the CPU contains a special bit called the carry bit If the sum of the leftmost digits (most significant bits) of two numbers produces a carry, the carry bit is set to 1, indicating the result was out of range 29

The carry bit and subtraction Instead of carries, binary subtraction (like decimal subtraction) is performed with borrows When a larger unsigned number is subtracted from a smaller unsigned number, the result would be negative, except there s no such thing as a negative unsigned number In other words, the result value would be out of range, and the carry bit is set to reflect this error condition 30