IKI10201 02-Data Types & Representations Bobby Nazief Semester-I 2005 - 2006 The materials on these slides are adopted from those in CS231’s Lecture Notes.

Slides:



Advertisements
Similar presentations
Binary Arithmetic Binary addition Binary subtraction
Advertisements

A digital system is a system that manipulates discrete elements of information represented internally in binary form. Digital computers –general purposes.
CHAPTER 2 Number Systems, Operations, and Codes
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Level ISA3: Information Representation
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
ECE 331 – Digital System Design
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
1 Number Systems. 2 Numbers Each number system is associated with a base or radix – The decimal number system is said to be of base or radix 10 A number.
Mantıksal Tasarım – BBM231 M. Önder Efe
Number Systems Lecture 02.
Binary Representation and Computer Arithmetic
Dr. Bernard Chen Ph.D. University of Central Arkansas
Data Representation Number Systems.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
CS231 Fundamentals1 Fundamentals What kind of data do computers work with? – Deep down inside, it’s all 1s and 0s What can you do with 1s and 0s? – Boolean.
Data Representation – Binary Numbers
Computer Arithmetic Nizamettin AYDIN
Logic and Digital System Design - CS 303
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
IT253: Computer Organization
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Chapter 2 Number Systems + Codes. Overview Objective: To use positional number systems To convert decimals to binary integers To convert binary integers.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
IKI a-Combinatorial Components Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes.
June 19, 2002Addition and multiplication1 Delays in the ripple carry adder The diagram below shows a 4-bit adder completely drawn out. This is called a.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
June 10, 2002© Howard Huang1 Number systems To get started, we’ll discuss one of the fundamental concepts underlying digital computer design:
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
CSC 331: DIGITAL LOGIC DESIGN COURSE LECTURER: E. Y. BAAGYERE. CONTACT: LECTURE TIME: 15:40 – 17:45 hrs. VENUE: SP-LAB.
Integer Operations Computer Organization and Assembly Language: Module 5.
BINARY SYSTEMS ENGR. KASHIF SHAHZAD 1. BINARY NUMBERS 1/2 Internally, information in digital systems is of binary form groups of bits (i.e. binary numbers)
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Binary Numbers The arithmetic used by computers differs in some ways from that used by people. Computers perform operations on numbers with finite and.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
CS231: Computer Architecture I Laxmikant Kale Fall 2002.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Unit 1 Introduction Number Systems and Conversion.
Negative Numbers and Subtraction
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Number Systems.
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Digital Logic & Design Lecture 02.
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
Presentation transcript:

IKI Data Types & Representations Bobby Nazief Semester-I The materials on these slides are adopted from those in CS231’s Lecture Notes at UIUC, which is derived from Howard Huang’s work and developed by Jeff Carlyle.

2 Road Map Boolean Algebra Logic Gates & Flip-flops Register-Transfer Design Finite-State Machines Binary Systems & Data Represent. Generalized FSM Sequential Design Techniques Logic Design Techniques Combinatorial Components Storage Components Processor Components

3 Number Systems To get started, we’ll discuss one of the fundamental concepts underlying digital computer design: Deep down inside, computers work with just 1s and 0s. Computers use voltages to represent information. In modern CPUs the voltage is usually limited to V to minimize power consumption. It’s convenient for us to translate these analog voltages into the discrete, or digital, values 1 and 0. But how can two lousy digits be useful for anything? – First, we’ll see how to represent numbers with just 1s and 0s. – Then we’ll introduce special operations for computing with 1s and 0s, by treating them as the logical values “true” and “false.” Volts

4 Positional number systems: decimal Numbers consist of a bunch of digits, each with a weight: The weights are all powers of the base, which is 10. We can rewrite the weights like this: To find the decimal value of a number, multiply each digit by its weight and sum the products. (1 x 10 2 ) + (6 x 10 1 ) + (2 x 10 0 ) + (3 x ) + (7 x ) + (5 x ) =

5 Positional number systems: binary We can use the same trick for binary, or base 2, numbers. The only difference is that the weights are powers of 2. For example, here is in binary: The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = = 13.25

6 Base 8 - Octal The octal system uses 8 digits: Earlier in this history of computing, octal was used as a shorthand for binary numbers. (Now hexadecimal is more common.) Since 8 = 2 3, one octal digit is equivalent to 3 binary digits. – Numbers like 67 are easier to work with than Still shows up in some places. For instance, file access permissions in Unix file systems.

7 Base 16 is useful too The hexadecimal system uses 16 digits: A B C D E F For our purposes, base 16 is most useful as a “shorthand” notation for binary numbers. – Since 16 = 2 4, one hexadecimal digit is equivalent to 4 binary digits. – It’s often easier to work with a number like B4 instead of Hex is frequently used to specify things like IPv6 addresses and 24-bit colors.

8 Converting decimal to binary To convert a decimal integer into binary, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts in forward order. Example: : So, = / 2= 81rem 0 81 / 2= 40rem 1 40 / 2= 20rem 0 20 / 2= 10rem 0 10 / 2= 5rem 0 5 / 2= 2rem 1 2 / 2= 1rem 0 1 / 2= 0rem x 2 = x 2 = x 2 = 1.000

9 Why does this work? This works for converting from decimal to any base Why? Think about converting from decimal to decimal. Each division strips off the rightmost digit (the remainder). The quotient represents the remaining digits in the number. Similarly, to convert fractions, each multiplication strips off the leftmost digit (the integer part). The fraction represents the remaining digits. 162 / 10= 16rem 2 16 / 10= 1rem 6 1 / 10= 0rem x 10 = x 10 = x 10 = 5.000

10 Binary and hexadecimal conversions Converting from hexadecimal to binary is easy: just replace each hex digit with its equivalent 4-bit binary sequence. To convert from binary to hex, make groups of 4 bits, starting from the binary point. Add 0s to the ends of the number if needed. Then, just convert each bit group to its corresponding hex digit = = = = B 4. 2 C 16

11 Practice Convert to hexadecimal. Convert CAFE 16 to decimal. Convert to base-12.

12 Convert to hexadecimal / 16 = 2006rem / 16 = 125rem / 16 = 7rem / 16 = 0rem * 16 = 8.0 So 7D

13 Convert CAFE 16 to decimal. 1. C: 12 * 16 3 = A: 10 * 16 2 = F: 15 * 16 1 = E: 14 * 16 - = =51966

14 Convert to base : 7 * 8 2 = : 0 * 8 1 = : 3 * 8 0 = = / 12 = 37rem / 12 = 3rem / 12 = 0rem 3 So

15 Number Systems Summary Computers are binary devices. – We’re forced to think in terms of base 2. – Today we learned how to convert numbers between binary, decimal and hexadecimal. We’ve already seen some of the recurring themes of architecture: – We use 0 and 1 as abstractions for analog voltages. – We showed how to represent numbers using just these two signals.

16 Additional information Assistants: – Panca Novianto: – Evan Jonathan Winata:

17 Review - Positional number systems: binary We can use the same trick for binary, or base 2, numbers. The only difference is that the weights are powers of 2. For example, here is in binary: The decimal value is: (1 x 2 3 ) + (1 x 2 2 ) + (0 x 2 1 ) + (1 x 2 0 ) + (0 x 2 -1 ) + (1 x 2 -2 ) = = 13.25

18 Review - Converting decimal to binary To convert a decimal integer into binary, keep dividing by 2 until the quotient is 0. Collect the remainders in reverse order. To convert a fraction, keep multiplying the fractional part by 2 until it becomes 0. Collect the integer parts in forward order. Example: : So, = / 2= 81rem 0 81 / 2= 40rem 1 40 / 2= 20rem 0 20 / 2= 10rem 0 10 / 2= 5rem 0 5 / 2= 2rem 1 2 / 2= 1rem 0 1 / 2= 0rem x 2 = x 2 = x 2 = 1.000

19 Addition and Subtraction of Binary Numbers Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures focus on addition and subtraction. Computers were designed to compute, so arithmetic is at the heart of a CPU.

20 Binary addition by hand You can add two binary numbers one column at a time starting from the right, just as you add two decimal numbers. But remember that it’s binary. For example, = 10 and you have to carry! 1110Carry in 1011Augend +1110Addend 11001Sum The initial carry in is implicitly 0 most significant bit, or MSB least significant bit, or LSB

21 Subtraction Computers do subtraction by adding the minuend with the negative representation of the subtrahend: – The main problem is representing negative numbers in binary. We introduce three methods, and show why one of them is the best. – With negative numbers, we’ll be able to do subtraction using the adders we made last time, because A - B = A + (-B).

22 Negative Numbers

23 Signed magnitude representation Humans use a signed-magnitude system: we add + or - in front of a magnitude to indicate the sign. We could do this in binary as well, by adding an extra sign bit to the front of our numbers. By convention: – A 0 sign bit represents a positive number. – A 1 sign bit represents a negative number. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit signed magnitude) 11101= (a negative number in 5-bit signed magnitude) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit signed magnitude) 10100= (a negative number in 5-bit signed magnitude)

24 Signed magnitude operations Negating a signed-magnitude number is trivial: just change the sign bit from 0 to 1, or vice versa. Adding numbers is difficult, though. Signed magnitude is basically what people use, so think about the grade-school approach to addition. It’s based on comparing the signs of the augend and addend: – If they have the same sign, add the magnitudes and keep that sign. – If they have different signs, then subtract the smaller magnitude from the larger one. The sign of the number with the larger magnitude is the sign of the result. This method of subtraction would lead to a rather complex circuit because

25 One’s complement representation A different approach, one’s complement, negates numbers by complementing each bit of the number. We keep the sign bits: 0 for positive numbers, and 1 for negative. The sign bit is complemented along with the rest of the bits. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit one’s complement) 10010= (a negative number in 5-bit one’s complement) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit one’s complement) 11011= (a negative number in 5-bit one’s complement)

26 Why is it called “one’s complement?” Complementing a single bit is equivalent to subtracting it from 1. 0’ = 1, and = 11’ = 0, and = 0 Similarly, complementing each bit of an n-bit number is equivalent to subtracting that number from 2 n -1. For example, we can negate the 5-bit number – Here n=5, and 2 n -1 = = – Subtracting from yields 10010:

27 One’s complement addition To add one’s complement numbers: – First do unsigned addition on the numbers, including the sign bits. – Then take the carry out and add it to the sum. Two examples: This is simpler and more uniform than signed magnitude addition. 0111(+7) (-4) (+3) (+2) (+5)

28 Two’s complement Our final idea is two’s complement. To negate a number, complement each bit (just as for ones’ complement) and then add 1. Examples: = (a 4-bit unsigned number) 01101= (a positive number in 5-bit two’s complement) 10010= (a negative number in 5-bit ones’ complement) 10011= (a negative number in 5-bit two’s complement) = 4 10 (a 4-bit unsigned number) 00100= (a positive number in 5-bit two’s complement) 11011= (a negative number in 5-bit ones’ complement) 11100= (a negative number in 5-bit two’s complement)

29 Two other equivalent ways to negate two’s complement numbers: – You can subtract an n-bit two’s complement number from 2 n. – You can complement all of the bits to the left of the rightmost = (a positive number in two’s complement) 10011= (a negative number in two’s complement) 00100= (a positive number in two’s complement) 11100= (a negative number in two’s complement) More about two’s complement ( ) 10011( ) (+4 10 ) 11100(-4 10 )

30 Comparing the signed number systems Here are all the 4-bit numbers in the different systems. Positive numbers are the same in all three representations. Signed magnitude and one’s complement have two ways of representing 0. This makes things more complicated. Two’s complement has asymmetric ranges; there is one more negative number than positive number. Here, you can represent -8 but not +8. However, two’s complement is preferred because it has only one 0, and its addition algorithm is the simplest.

31 Converting signed numbers to decimal Convert to decimal, assuming this is a number in: (a) signed magnitude format (b) ones’ complement (c) two’s complement

32 Example solution Convert to decimal, assuming this is a number in: Since the sign bit is 1, this is a negative number. The easiest way to find the magnitude is to convert it to a positive number. (a) signed magnitude format Negating the original number, , gives , which is in decimal. So must represent (b) ones’ complement Negating in ones’ complement yields = , so the original number must have been (c) two’s complement Negating in two’s complement gives = 11 10, which means = The most important point here is that a binary number has different meanings depending on which representation is assumed.

33 Addition: – Just add the two numbers – Ignore the Carry-out from MSB – Result will be correct, provided there’s no overflow (+5) (+2) (+7) (+5) (-6) (-1) (-5) (-2) (-7) (+7) (-3) (+4) (+2)  (+4) (-4) (-2) (-2)  (-5) (+5) (+3) Subtraction: – Form 2’s complement of the subtrahend – Add the two numbers as in Addition Addition & Subtraction of 2’s complement numbers

34 Examples: = 10 but – 5 = - 9 but... 2’s ComplementBinaryDecimal Decimal – 6 – 4 – 5 7 Overflow

35 Binary Multiplication Since we always multiply by either 0 or 1, the partial products are always either 0000 or the multiplicand (1101 in this example). There are four partial products which are added to form the result. 1101Multiplicand x0110Multiplier 0000Partial products Product

36 Shifting the multiplicand 1101Multiplicand x0110Multiplier 0000first partial products +0000shifted zeros 0000second partial products +1101shifted multiplicand 11010third partial products +1101shifted multiplicand fourth partial products +0000shifted zeros Product

37 Binary Division

38 Floating-Point Numbers

x radix (base) decimal pointmantissa exponent Normalized form: no leadings 0s (exactly one digit to left of decimal point) Alternatives to representing 1/1,000,000,000 – Normalized: 1.0 x – Not normalized: 0.1 x 10 -8,10.0 x Scientific notation review

two x 2 -1 radix (base) “binary point”Mantissa exponent Computer arithmetic that supports it called floating point, because it represents numbers where binary point is not fixed, as it is for integers – Declare such variable in C as float Scientific notation for binary numbers

41 Normal format: +1.xxxxxxxxxx two *2 yyyy two Multiple of Word Size (32 bits) 31 0 SExponent 189 Significand 1 bit8 bits23 bits S represents Sign Exponent represents y’s Significand represents x’s Represent numbers as small as 2.0 x to as large as 2.0 x Floating point representation

42 BCD

43 Character Codes

44 Codes for Error Detection & Correction Please read yourself.

45 Hamming Codes Please read yourself.