Number Representation. 10/12/2015CDA31002 Conversion between Representations Now we can represent a quantity in different number representations How can.

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

Chapter 2 : Number System
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Kavita Hatwal Fall The decimal system, also called the base 10 number system is based on ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All the numbers.
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Chapter 02 Binary Values and Number Systems Nell Dale & John Lewis.
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.
Review Binary Basic Conversion Binary Decimal
Binary Numbers.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Systems 1 Fundamentals of Computing Negative Binary.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Simple Data Type Representation and conversion of numbers
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Number Systems Binary and Hexadecimal. Base 2 a.k.a. Binary  Binary works off of base of 2 instead of a base 10 like what we are taught in school 
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Computer Science 111 Fundamentals of Programming I Number Systems.
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
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.
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.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Number systems, Operations, and Codes
Operations on Bits Arithmetic Operations Logic Operations
Microcomputers I - Electrical and Computer Engineering Dept. at Kettering.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Chapter 3 Complements Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
AEEE2031 Data Representation and Numbering Systems.
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=
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
NUMBER SYSTEMS.
Introduction To Number Systems Binary System M. AL-Towaileb1.
CDA 3100 Spring Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
CDA 3100 Fall2009. Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
EEE342 Digital Electronics Ian McCrumRoom 5B18, Lecture 2: Codes & Arithmetic.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Numbers in Computers.
CSC 331: DIGITAL LOGIC DESIGN COURSE LECTURER: E. Y. BAAGYERE. CONTACT: LECTURE TIME: 15:40 – 17:45 hrs. VENUE: SP-LAB.
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.
Lecture 2: 8/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Number Systems. ASCII – American Standard Code for Information Interchange – Standard encoding scheme used to represent characters in binary format on.
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.
CDA 3100 Fall Special Thanks Thanks to Dr. Xiuwen Liu for letting me use his class slides and other materials as a base for this course.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Week 1(Number System) Muhammad Ammad uddin Logic Design Lab I (CEN211)
Representing Positive and Negative Numbers
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
Introduction To Number Systems
Chapter 3 Data Representation
Number Representation
CDA 3100 Summer 2013.
Digital Logic & Design Lecture 02.
Unit 18: Computational Thinking
2’s Complement form 1’s complement form 2’s complement form
Binary to Decimal Conversion
CDA 3100 Fall 2012.
Presentation transcript:

Number Representation

10/12/2015CDA31002 Conversion between Representations Now we can represent a quantity in different number representations How can we convert a decimal number to binary? How can we then convert a binary number to a decimal one?

Conversion From Binary to Decimal Converting from binary to decimal. This conversion is based on the formula: d = d n-1 2 n-1 + d n-2 2 n-2 +…+ d d d while remembering that the digits in the binary representation are the coefficients. For example, given two, in decimal, it is = 43.

Conversion From Decimal to Binary Converting from decimal to binary: Repeatedly divide it by 2, until the quotient is 0. Write down the remainder, the last remainder first. Example: 11 ten is 1011 two QuotientRemainder

Conversion From Decimal to Binary Why can a binary number be obtained by keeping on dividing it by 2, and why should the last remainder be the first bit? The decimal number can be represented by the summation of the powers of 2: d = d n-1 2 n-1 + d n-2 2 n-2 +…+ d d d For example, 19 = = 1 * * * * * 2 0. The binary representation is the binary coefficients. So 19 ten in binary is two. So the conversion is to find the coefficients. Easiest way to do so is to repeatedly divide it by 2. For example, 19 = 1 * * How do you get the 1 and 9? You divide 19 by 10 repeatedly until the quotient is 0, same as binary!

Conversion between Base 16 and Base 2 Extremely easy. From base 2 to base 16: divide the digits in to groups of 4, then apply the table. From base 16 to base 2: replace every digit by a 4-bit string according to the table. Because 16 is 2 to the power of 4.

Addition in binary 39 ten + 57 ten = ? How to do it in binary?

Addition in Binary First, convert the numbers to binary forms. We are using 8 bits. 39 ten -> ten -> Second, add them

Addition in binary The addition is bit by bit. We will encounter at most 4 cases, where the leading bit of the result is the carry: = = = =11

Subtraction in Binary 57 ten – 39 ten = ?

Subtraction in Binary

Subtraction in binary Do this digit by digit. No problem if = 0, = 1 1 – 1 = 0. When encounter 0 - 1, set the result to be 1 first, then borrow 1 from the next more significant bit, just as in decimal. Borrow means setting the borrowed bit to be 0 and the bits from the bit following the borrowed bit to the bit before the current bit to be 1. Think about, for example, subtracting 349 from 5003 (both based 10). The last digit is first set to be 4, and you will be basically subtracting 34 from 499 from now on.

10/12/2015CDA Signed Numbers Two’s complement in n bits: The negative of a two’s complement is given by inverting each bit (0 to 1 or 1 to 0) and then adding 1, ignore any carry beyond n bits (take only the lower n bits). If numbers are represented in n bits: the positive numbers are from 0000…01 to 0111…11, 0 is all 0: 0000…00, the negative numbers are from 1000…00 to 1111…11. The leading bit is called the “sign bit”: 0 means non-negative, 1 means nagative

Signed numbers What is (-57 ten ) in binary in 8 bits? (57 ten in binary) (invert) (add 1)

Question What is the range of numbers represented by 2’s complement with 4 bits? The answer is [-8,7]. This is because all numbers with leading bit being 1 are negative numbers. So we have 8 of them. Then 0 is all 0. Then seven positive numbers.

10/12/2015CDA Two’s Complement Representation Type (C)Number of bitsRange (decimal) char8-128 to 127 short to int32-2,147,483,648 to 2,147,483,647 long 64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 n+1 bits (in general)n+1-2 n to 2 n - 1

Why use 2’s complement? ( Not required ) If you think about it, x in 2’s complement with n bits is just 2 n -x. Consider (– 00011) = – = (13-3=10 in decimal) – = – – = ( – 00011) – = – = – = is the 2’s complement of Means that computer (the adder) does not have to be specifically redesigned for dealing with negative numbers, make life easier for the computer The reason is, assume you are subtracting a with b, where 2^{n-1}>a>b>0. Note that a-b=a+2^{n}-b-2^{n}. But 2^{n}-b is the 2’s complement of b. So if represented in binary forms, a+2^{n}-b will be having a 1 bit in bit n and some thing in bit 0 to bit n-2 equal to a-b. Bit n-1 will be 0. So you take what is in bit 0 to bit n and it must be a-b.

Subtraction with 2’s Complement How about 39 ten + (-57 ten )?

Subtraction with 2’s Complement First, what is (-57 ten ) in binary in 8 bits? (57 ten in binary) (invert) (add 1) Second, add them

Converting 2’s complement to decimal What is ten in decimal if it represents a two’s complement number? (original) (after minus 1) (after inversion)

10/12/2015CDA Two’s Complement Representation Sign extension We often need to convert a number in n bits to a number represented with more than n bits From char to int for example This can be done by taking the most significant bit from the shorter one and replicating it to fill the new bits of the longer one Existing bits are simply copied

10/12/2015CDA Sign Extension Example ten How about unsigned numbers?

10/12/2015CDA Sign Extension Example: Unsigned ten

10/12/2015CDA Unsigned and Signed Numbers Note that bit patterns themselves do not have inherent meaning We also need to know the type of the bit patterns For example, which of the following binary numbers is larger?

10/12/2015CDA Unsigned and Signed Numbers Note that bit patterns themselves do not have inherent meaning We also need to know the type of the bit patterns For example, which one is larger? Unsigned numbers? Signed numbers?