S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

Chapter 2 : Number System
CHAPTER 2 Number Systems, Operations, and Codes
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Wael Qassas/AABU.
Number Systems Standard positional representation of numbers:
Introduction to Programming with Java, for Beginners
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
Data Representation in Computers
Digital Fundamentals Floyd Chapter 2 Tenth Edition
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Data Representation – Chapter 3 Sections 3-2, 3-3, 3-4.
Number Systems Lecture 02.
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we.
Binary Number Systems.
1.6 Signed Binary Numbers.
Dr. Bernard Chen Ph.D. University of Central Arkansas
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
Logic and data representation Revision. AND gate A B A B All inputs have to be true ( i.e 1) for the output of the gate to be high, in all other cases.
Computer Arithmetic Nizamettin AYDIN
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
Computer Architecture
Data Representation and Computer Arithmetic
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Idea 1: Bits Two states in a digital machine: 1.presence of.
Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we represent.
Number Systems Spring Semester 2013Programming and Data Structure1.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
PART 2 Data Types 1. Integers 2. 2’s Complement 3. Conversion
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Chapter 2 Bits, Data Types, and Operations. 2-2 Hexadecimal Notation It is often convenient to write binary (base-2) numbers as hexadecimal (base-16)
Bits, Data Types, and Operations Slides based on set prepared by Gregory T. Byrd, North Carolina State University.
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.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Number systems, Operations, and Codes
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Chapter 2 Bits, Data Types, and Operations. 2-2 How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Number Systems and Digital Codes
AEEE2031 Data Representation and Numbering Systems.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
Instructor:Po-Yu Kuo 教師:郭柏佑
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
NUMBER SYSTEMS AND CODES. CS Digital LogicNumber Systems and Codes2 Outline Number systems –Number notations –Arithmetic –Base conversions –Signed.
Number Representation and Arithmetic Circuits
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.
N 3-1 Data Types  Binary information is stored in memory or processor registers  Registers contain either data or control information l Data are numbers.
CHAPTER 1 : INTRODUCTION
CS1010 Programming Methodology
Data Representation Data Types Complements Fixed Point Representation
Numbering System TODAY AND TOMORROW 11th Edition
Data Representation – Chapter 3
Presentation transcript:

S. Barua – CPSC CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems Integer data types Unsigned integers Signed integers Signed-magnitude 1’s complement 2’s complement 2’s complement integers Number base conversions Arithmetic operations Status bits – Negative, Zero, Carry, & Overflow Floating point data type ASCII code

S. Barua – CPSC Number Systems Used in a Computer The most commonly used number systems in digital computers are: Decimal Binary Octal Hexadecimal Number System Radix (base) Digits used Decimal 10 0, 1,.....,9 Binary 2 0, 1 Octal 8 0, 1,......, 7 Hexadecimal 16 0, 1,....., 9, A, B,....., F

S. Barua – CPSC Unsigned Integers No distinction is made between positive and negative numbers. An unsigned integer S can be represented as: S = s n-1 s n s 1 s 0 r where s i = digits allowed in the corresponding number system for S n = number of integer digits r = radix (base) of the number system Examples:S = S = S = S = 2CD59 16

S. Barua – CPSC Signed Integers When it becomes necessary to specify the sign of a number (positive or negative) the following two representations can be employed. Signed-magnitude representation Complement representation 1’s complement 2’s complement

S. Barua – CPSC Signed Integers: Signed-magnitude Representation An additional binary bit (sign bit) is added to the most significant bit position of the binary string that represents the magnitude. The sign bit will be 0 for a positive binary number and 1 for a negative binary number. Example:S = S =

S. Barua – CPSC Complement Representation 1’s complement of a binary number Simply complement the individual bits of the binary number. Example:Let N 2 = (unsigned) 1’s complement of N 2 = ? 2’s complement of a binary number Add a 1 to the 1’s complement. Example:Let N 2 = (Unsigned) 2’s complement of N 2 = ?

S. Barua – CPSC ’s complement Integers The 2’s complement integer representation of a positive number is: 2’s complement integer = s N where“s”, the sign bit = 0 N is the magnitude, in binary, of the given number The 2’s complement integer representation of a negative number is: 2’s complement integer = s [2’s complement of N] where “s”, the sign bit = 1 N is the magnitude, in binary, of the given number

S. Barua – CPSC ’s complement Integers (Continued) Example 1: Compute the 2’s complement integer representation of the decimal number +232 Example 2: Compute the 2’s complement integer representation of the decimal number -232

S. Barua – CPSC Number Base Conversions Binary to Decimal Conversion 1. If leading bit (most significant bit, MSB) is 1, take two’s complement of the magnitude bits to get a positive number. 2. Add powers of 2 that have “1” s in the corresponding bit positions. 3. If original number was negative, add a minus sign.

S. Barua – CPSC Binary to Decimal Conversion - Examples Example 1: Let N 2 = Compute N 10. Example 2: Let N 2 = Compute N 10. Example 3: Let N 2 = Compute N 10.

S. Barua – CPSC Number Base Conversions (Continued) Decimal to Binary Conversion Method used: Repeated Division 1. Divide the magnitude of the decimal number by 2. The remainder is the least significant bit (LSB) of the binary. 2. Keep dividing by 2 until the answer is zero, writing the remainders from right to left. 3. Append a zero as the MSB. 4. If the original number was negative, take 2’s complement of the result generated in step 3.

S. Barua – CPSC Decimal to Binary Conversion - Examples Example 1: Let N 10 = 104. Compute N 2. Example 2: Let N 10 = Compute N 2.

S. Barua – CPSC Number Base Conversions (Continued) Hexadecimal to Binary Conversion Each hexadecimal digit corresponds to a group of 4 binary bits. Method used: Bit Grouping To convert a hexadecimal number to binary, represent each hexadecimal digit by the equivalent 4- bit binary.

S. Barua – CPSC Hexadecimal to Binary Conversion - Example Example: Let N 16 = 1A4C2. Compute N 2.

S. Barua – CPSC Number Base Conversions (Continued) Binary to Hexadecimal Conversion A group of 4 binary bits corresponds to a hexadecimal digit. Method used: Bit Grouping To convert a binary number to hexadecimal: Split up the binary number into 4-bit groups starting from the LSB Replace each binary group with the corresponding hexadecimal digit

S. Barua – CPSC Binary to Hexadecimal Conversion - Example Example: Let N 2 = Compute N 16.

S. Barua – CPSC Arithmetic Operations Arithmetic on 2’s complement numbers is very much like the arithmetic on decimal numbers. Steps for Addition and Subtraction: 1. Express the given binary numbers as 2’s complement numbers 2. Add the numbers obtained step 1 3. Discard the end carry, if any 4. Express the result in signed-magnitude

S. Barua – CPSC Arithmetic Operation - Example Example: Perform the following arithmetic operation using a 9-bit representation: N =

S. Barua – CPSC Arithmetic Operation - Example Example: Perform the following arithmetic operation using an 8-bit representation: N =

S. Barua – CPSC Status Bits Status bits are used to specify the nature of the result generated during an arithmetic or logic operation. Most common status bits are: Negative (N) bit N = 1 if the result is negative, 0 otherwise Zero (Z) bit Z = 1 if the result is zero; 0 otherwise Carry (C) bit C = 1 if there is an end carry; 0 otherwise Overflow (V) bit V = 1 if the result is out of range; 0 otherwise

S. Barua – CPSC The Overflow Bit If operands are too big, then the sum cannot be represented as an n-bit 2’s complement number. An overflow condition occurs when the result of an operation is out of range. We have overflow if: – signs of both operands are the same, and – sign of the sum is different. The overflow bit (V bit) detects overflow for signed numbers If the carry into the MSB bit does not equal to the carry out an overflow has occurred and V is set to 1. If they are the same, V is set to 0.

S. Barua – CPSC Overflow - Examples We have overflow if: – signs of both operands are the same, and – sign of the sum is different. (a) (8) (b) (-8) (9) (-9) (-15)01111 (+15) (a)N = 1Z = 0C = 0V = 1 (b) N = 0Z = 0C = 1V = 1

S. Barua – CPSC Represents numbers with fractional components Very much like the equivalent of “scientific notation”: F x 2 E Need to represent F (fraction), E (exponent), and sign Floating Point Data Type

S. Barua – CPSC Floating Point Data Type (Continued) IEEE 754 Floating-Point Standard (32-bits): SExponentFraction 1823 bits

S. Barua – CPSC Floating Point Data Type (Continued) Example: How is the decimal number represented in the floating point data type? Solution: 1. Express the decimal number in binary = Normalize the value: Determine the exponent field content Exponent – 127 = 3 Therefore, Exponent = = 130 (Unsigned) = Express the fraction using 23 bits Fraction = Sign bit = 0 because the given decimal number is a positive number So, the floating point data type for the decimal number is

S. Barua – CPSC Floating Point Data Type (Continued) Example: What does the the floating point data type Represent? Solution: Given floating point data type: Sign is1. This means the number is negative. Exponent field is = 126 (decimal, unsigned) Therefore, the real exponent = 126 – 127 = -1 Fraction is represented by the 23 bits = Therefore, the number being represented is: = =

S. Barua – CPSC Floating Point Data Type (Continued) Please review the following examples from the text book: Example 2.12 (Page 39 of the textbook) – 1 problem Example 2.13 (Page 39 of the textbook) – 2 problems Example 2.14 (Page 40 of the textbook) – 4 problems

S. Barua – CPSC ASCII Codes ASCII codes are used when the computing device has to handle letters and special symbols as well as decimal digits. ASCII - American Standard Code for Information Interchange ASCII maps 128 characters to 7-bit code.

S. Barua – CPSC Text: ASCII Characters 01soh11dc121!31141A51Q61a71q 02stx12dc222"32242B52R62b72r 03etx13dc323#33343C53S63c73s 04eot14dc424$34444D54T64d74t 05enq15nak25%35545E55U65e75u 06ack16syn26&36646F56V66f76v 07bel17etb27'37747G57W67g77w 08bs18can28(38848H58X68h78x 09ht19em29)39949I59Y69i79y 0anl1asub2a*3a:4aJ5aZ6aj7az 0bvt1besc2b+3b;4bK5b[6bk7b{ 0cnp1cfs2c,3c<4cL5c\6cl7c| 0dcr1dgs2d-3d=4dM5d]6dm7d} 0eso1ers2e.3e>4eN5e^6en7e~ 0fsi1fus2f/3f?4fO5f_6fo7fdel

S. Barua – CPSC ASCII Codes & Parity Bit ASCII is a 7-bit representation Parity bit is added to the ASCII, as the most significant bit, to give the ASCII an 8-bit representation Two types of parity – Even & Odd Even Parity – The total number of 1s in the 8-bit representation is an even number Odd Parity – The total number of 1s in the 8-bit representation is an odd number