ECE 2110: Introduction to Digital Systems Signed Number Conversions.

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Representations Example: Numbers –145 –CVL – –91 –
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Introduction to Number Systems
3. Representing Integer Data
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Systems 1 Fundamentals of Computing Negative Binary.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
ECE 3110: Introduction to Digital Systems Review #1 (Chapter 1,2)
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
ICS312 Set 1 Representation of Numbers and Characters.
Lecture Objectives: 1)Define the terms least significant bit and most significant bit. 2)Explain how unsigned integer numbers are represented in memory.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
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.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
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.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
The Teacher CP4 Binary and all that… CP4 Revision.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
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.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
The Teacher CP4 Binary and all that… CP4 Revision.
INEL 4215: Computer Architecture and Organization Number Systems Signed numbers.
AEEE2031 Data Representation and Numbering Systems.
ECE 2110: Introduction to Digital Systems
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
Digital Design Basics Analog vs Digital Why we need digital? Reproducibility, economy, programmability… Digital Devices Gates, FFs Combinational, sequential.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
ECE 3110: Introduction to Digital Systems Number Systems.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
ECE 2110: Introduction to Digital Systems
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Starter Using the mini whiteboards record your answers: 1) Name 2 different Character Sets 2) Convert the Hex number 9E into denary 3) Convert the binary.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
Advanced Binary b. describe and use two’s complement and sign and magnitude to represent negative integers; c. perform integer binary arithmetic, that.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
ECE 3110: Introduction to Digital Systems
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
ECE 2110: Introduction to Digital Systems
ECE 3110: Introduction to Digital Systems
ECE 331 – Digital System Design
Presentation transcript:

ECE 2110: Introduction to Digital Systems Signed Number Conversions

2 Previous class Summary Signed-magnitude, two’s complement, one’s complement Different for negatives numbers Representations of positive numbers are SAME. 0 may have different representations. Sign bit: 0 for positive, 1 for negative

3 Signed Decimal to Hex conversion Step 1: Know what format you are converting to!!! You must know if you are converting the signed decimal to SM, 1s complement, or 2s complement. Convert +34, -20 to all three formats. Step 2: Ignore the sign, convert the magnitude to binary. 34 = 2 x = = = 1 x = = Step 3 (positive decimal number): If the decimal number was positive, then you are finished no matter what the format is! +34 as an 8 bit SM number is = as an 8 bit 1s complement number is = as an 8 bit 2s complement number is =

4 Signed Decimal to Hex conversion (cont) Step 3 (negative decimal number): Need to do more if decimal number was negative. If converting to SM format, set Sign bit to One: 20 = , then -20 => = If converting to 1s complement, complement each bit. 20 = , then -20 => = EB 16 If converting to 2s complement, complement and add one. 20 = , then -20=> = = EC 16

5 Signed Decimal to Hex conversion (cont) Final results: Compare! +34 as an 8 bit SM number is = as an 8 bit 1s complement number is = as an 8 bit 2s complement number is = as an 8 bit SM number is = as an 8 bit 1s complement number is EB 16 = as an 8 bit 2s complement number is EC 16 =

6 Sign extension? Pad with 0s for positive numbers and 1s for negative numbers

7 A common Question? Given a hex number, how do I know if it is in 2’s complement or 1’s complement; is it already in 2’s complement or do I have put it in 2’s complement, etc.

8 Answer: We cant! If I write a HEX number, I will ask for a decimal representation if you INTERPRET the encoding as a particular method (i.e, either 2’s complement, 1’s complement, signed magnitude). A Hex or binary number BY ITSELF can represent ANYTHING (unsigned number, signed number, character code, etc). You MUST HAVE additional information that tells you what the encoding of the bits mean. For example: FE 16 or

9 Example Conversions FE 16 as an 8 bit unsigned integer = 254 FE 16 as an 8 bit signed magnitude integer = -126 FE 16 as an 8 bit ones complement integer = - 1 FE 16 as an 8 bit twos complement integer = -2 7F 16 as an 8 bit unsigned integer = 127 7F 16 as an 8 bit signed magnitude integer = F 16 as an 8 bit ones complement integer = F 16 as an 8 bit twos complement integer = +127 To do hex to signed decimal conversion, we need to determine sign (Step 1), determine Magnitude (step 2), combine sign and magnitude (Step 3)

10 Hex to Signed Decimal Conversion Rules Given a Hex number, and you are told to convert to a signed integer (either as signed magnitude, 1s complement, 2s complement) STEP 1: Determine the sign! If the Most Significant Bit is zero, the sign is positive. If the MSB is one, the sign is negative. This is true for ALL THREE representations: SM, 1s complement, 2s complement. F0 16 = (MSB is ‘1’), so sign of result is ‘-’ = (MSB is ‘0’), so sign of result is ‘+’. If the Most Significant Hex Digit is > 7, then MSB = ‘1’ !!! (e.g., 8,9,A,B,C,D,E,F => MSB = ‘1’ !!!)

11 Hex to Signed Decimal (cont) STEP 2 (positive sign): If the sign is POSITIVE, then just convert the hex value to decimal. The representation is the same for SM, 1s complement, 2s complement is a positive number, decimal value is 6 x = 100. STEP 3 : Just combine the sign and magnitude to get the result as an 8 bit signed magnitude integer = as an 8 bit ones complement integer = as an 8 bit twos complement integer = +100 Note: Final answer is +100 regardless of whether encoding was SM, 1s complement, or 2s complement.

12 Hex to Signed Decimal (cont) STEP 2 (negative sign): If the sign is Negative, then need to compute the magnitude of the number. We will use the trick that - (-N) = + N i.e. Take the negative of a negative number will give you the positive number. In this case the number will be the magnitude. If the number is SM format, set Sign bit to Zero: F0 16 = => = = 112 If the number is 1s complement, complement each bit. F0 16 = => = 0F 16 = 15 If the number is 2s complement, complement and add one. F0 16 = => = = = 16

13 Hex to Signed Decimal (cont) STEP 3 (also): Just combine the sign and magnitude to get the result. F0 16 as 8 bit Signed magnitude number is -112 F0 16 as 8 bit ones complement number is -15 F0 16 as 8 bit twos complement number is -16

14 Next… Quiz#1 Signed Addition/Subtraction