ECE 2110: Introduction to Digital Systems Signed Number Conversions.

Slides:



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

CS 151 Digital Systems Design Lecture 3 More Number Systems.
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.
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
Computer Systems 1 Fundamentals of Computing Negative Binary.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
ECE 3110: Introduction to Digital Systems Review #1 (Chapter 1,2)
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,
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.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
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.
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.
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.
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=
ECE 3110: Introduction to Digital Systems Number Systems.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
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.
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.
ECE 2110: Introduction to Digital Systems Number Systems: conversions.
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.
ECE 3110: Introduction to Digital Systems
Chapter 2 Binary Number Systems.
Signed binary numbers & Binary Codes
ECE 2110: Introduction to Digital Systems
NUMBER SYSTEMS.
Lec 3: Data Representation
Data Representation.
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Conversion, Carry and Overflow
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Computer Science 210 Computer Organization
Numbers in a Computer Unsigned integers Signed magnitude
Logistics Always read the Calendar at
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
Addition and Substraction
ECE 2110: Introduction to Digital Systems
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
Computer Science 210 Computer Organization
ECE 3110: Introduction to Digital Systems
How are negative and rational numbers represented on the computer?
Homework Homework Continue Reading K&R Chapter 2 Questions?
CPS120: Introduction to Computer Science
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
ECE 331 – Digital System Design
Numbers and Arithmetic and Logical Operation
Lecture No.5.
Two’s Complement & Binary Arithmetic
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 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.

4 Answer 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

5 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)

6 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’ !!!)

7 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. Final answer is +100 regardless of whether encoding was SM, 1s complement, or 2s complement as an 8 bit signed magnitude integer = as an 8 bit ones complement integer = as an 8 bit twos complement integer = +100

8 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

9 Hex to Signed Decimal (cont) STEP 3 : 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 as an 8 bit signed magnitude integer = as an 8 bit ones complement integer = as an 8 bit twos complement integer = +100

10 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 =

11 Signed Decimal to Hex conversion (cont) Step 3 (negative decimal number): Need to do more if decimal number was negative. To get the final representation, we will use the trick that: - (+N) = -N i.e., if you take the negative of a positive number, get Negative number. If converting to SM format, set Sign bit to One: 20 = => = If converting to 1s complement, complement each bit. 20 = => = EB 16 If converting to 2s complement, complement and add one. 20 = => = % = EC 16

12 Signed Decimal to Hex conversion (cont) Final results: +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 =

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

14 Next… Signed Addition/Subtraction