Binary numbers and arithmetic

Slides:



Advertisements
Similar presentations
Appendix 1 Number Systems Objectives: Review of number systems and radix conversion methods Review of binary, octal, hexadecimal and BCD unsigned codes.
Advertisements

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.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
Floating Point Numbers
Quiz 1.1 Convert the following unsigned binary numbers to their decimal equivalent: Number2 Number
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Binary Number Systems.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Binary numbers and arithmetic. ADDITION Addition (decimal)
The Binary Number System
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Computer Number Systems. d n-1 d n-2 d n d 2-m d 1-m d -m Conventional Radix Number r is the radixd i is a digit d i Є {0, 1, ….., r – 1 } -m ≤
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=
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Negative Integer Representation.
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 3110: Introduction to Digital Systems Number Systems: signed numbers.
Computer Organization 1 Data Representation Negative Integers.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
973cs111_add_posneg.ppt Integers Whole numbers Do NOT contain decimal points (as in money) 43,689 is an integer 43, is NOT an integer (it is floating.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Arithmetic – Part I
CHAPTER 5: Representing Numerical Data
Topic: Binary Encoding – Part 2
Binary & Hex Review.
Backgrounder: Binary Math
David Kauchak CS 52 – Spring 2017
Signed binary numbers & Binary Codes
Computer Architecture & Operations I
Array multiplier TU/e Processor Design 5Z032.
Negative numbers: Week 10 Lesson 1
Negative Binary Numbers
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Computer Science 210 Computer Organization
Numbers in a Computer Unsigned integers Signed magnitude
Computer Architecture & Operations I
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
Bit Operations Horton pp
CHAPTER 4: Representing Integer Data
Overview Introduction Data representation Fixed Point Representation
CS1010 Programming Methodology
ECE 2110: Introduction to Digital Systems
Wakerly Section 2.4 and further
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Computer Science 210 Computer Organization
Number Systems and Circuits for Addition – Negative Integers
Negative Integer Representation
Topic 3 Number Representations and Computer Arithmetics
Assembler (assembly language)
CSE 311: Foundations of Computing
Computer Architecture
EEL 3705 / 3705L Digital Logic Design
ECE 3110: Introduction to Digital Systems
Topic 3 Number Representations and Computer Arithmetics
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Chapter 1 Number System RGGP, Narwana.
Chapter 6: Computer Arithmetic
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
CSC 220: Computer Organization Signed Number Representation
Lecture No.5.
Lecture 2: Bits, Bytes, Ints
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Bit Operations Horton pp
Today Binary addition Representing negative numbers 2.
Presentation transcript:

Binary numbers and arithmetic

Addition (decimal)

Addition (binary)

Addition (binary)

Multiplication (decimal)

Multiplication (binary)

Multiplication (binary) It’s interesting to note that binary multiplication is a sequence of shifts and adds of the first term (depending on the bits in the second term. The first term is missing here because the corresponding bit in the second terms is 0.

Representing numbers (ints) Fixed, finite number of bits. bits bytes C/C++ Intel Sun 8 1 char [s]byte byte 16 2 short [s]word half 32 4 int or long [s]dword word 64 8 long long [s]qword xword

Representing numbers (ints) Fixed, finite number of bits. bits Intel signed unsigned 8 [s]byte -27..+27-1 0..+28-1 16 [s]word -215..+215-1 0..+216-1 32 [s]dword -231..+231-1 0..+232-1 64 [s]qword -263..+263-1 0..+264-1 In general, for k bits, the unsigned range is [0..+2k-1] and the signed range is [-2k-1..+2k-1-1].

Methods for representing signed ints. signed magnitude 1’s complement (diminished radix complement) 2’s complement (radix complement) excess bD-1

Signed magnitude Ex. 4-bit signed magnitude 1 bit for sign 3 bits for magnitude

Signed magnitude Ex. 4-bit signed magnitude 1 bit for sign 3 bits for magnitude

1’s complement (diminished radix complement) Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base D = (total) # of bits (including the sign bit) Ex. Let b=2 and D=4. Then -1 is represented by 24-1-1 = 1410 or 11102.

1’s complement (diminished radix complement) Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base & D = (total) # of bits (including the sign bit) Ex. What is the 9’s complement of 1238910? Given b=10 and D=5. Then the 9’s complement of 12389 = 105 – 1 – 12389 = 100000 – 1 – 12389 = 99999 – 12389 = 87610

1’s complement (diminished radix complement) Let x be a non-negative number. Then –x is represented by bD-1+(-x) where b = base D = (total) # of bits (including the sign bit) Shortcut for base 2? Ex. Let b=2 and D=4. Then -1 is represented by 24-1-1 = 1410 or 11102.

2’s complement (radix complement) Let x be a non-negative number. Then –x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or 11112. Ex. Let b=2 and D=4. Then -5 is represented by 24 – 5 = 11 or 10112. Ex. Let b=10 and D=5. Then the 10’s complement of 12389 = 105 – 12389 = 100000 – 12389 = 87611.

2’s complement (radix complement) Let x be a non-negative number. Then –x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or 11112. Ex. Let b=2 and D=4. Then -5 is represented by 24 – 5 = 11 or 10112. Shortcut for base 2?

excess bD-1 For pos, neg, and 0, x is represented by bD-1 + x. Ex. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or 10002. Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 – 1 = 7 or 01112.

excess bD-1 For pos, neg, and 0, x is represented by bD-1 + x. Ex. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or 10002. Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 – 1 = 7 or 01112.

Summary of methods for representing signed ints.

Representing numbers (ints) Fixed, finite number of bits. bits Intel signed 8 sbyte -27..+27-1 16 sword -215..+215-1 32 sdword -231..+231-1 64 sqword -263..+263-1 In general, for k bits, the signed range is [-2k-1..+2k-1-1]. So where does the extra negative value come from?

Representing numbers (ints) Fixed, finite number of bits. bits Intel signed 8 sbyte -27..+27-1 16 sword -215..+215-1 32 sdword -231..+231-1 64 sqword -263..+263-1 In general, for k bits, the signed range is [-2k-1..+2k-1-1]. So where does the extra negative value come from?