Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

Similar documents
ENGIN 112 Intro to Electrical and Computer Engineering

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

Conversions between Decimal and Binary

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

Chapter 1 CSCI

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

12/31/2010. Digital Operations and Computations Course Notes. 01-Number Systems Text: Unit 1. Overview. What is a Digital System?

0,..., r 1 = digits in radix r number system, that is 0 d i r 1 where m i n 1

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Complement Arithmetic

CHAPTER 2 NUMBER SYSTEMS

Week No. 06: Numbering Systems

ENGIN 112 Intro to Electrical and Computer Engineering

What are binary numbers and why do we use them? BINARY NUMBERS. Converting decimal numbers to binary numbers

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Digital Systems Overview. Unit 1 Numbering Systems. Why Digital Systems? Levels of Design Abstraction. Dissecting Decimal Numbers

THE LOGIC OF COMPOUND STATEMENTS

Hakim Weatherspoon CS 3410 Computer Science Cornell University

hexadecimal-to-decimal conversion

Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

convert a two s complement number back into a recognizable magnitude.

ECE380 Digital Logic. Positional representation

CSEN102 Introduction to Computer Science

Fundamentals of Digital Design

REVIEW Chapter 1 The Real Number System

Four Important Number Systems

We say that the base of the decimal number system is ten, represented by the symbol

NUMBERS AND CODES CHAPTER Numbers

Combinational Logic. By : Ali Mustafa

Number Bases. Ioan Despi. University of New England. August 4, 2013

Chapter 2 (Part 3): The Fundamentals: Algorithms, the Integers & Matrices. Integers & Algorithms (2.5)

Binary addition example worked out

Cs302 Quiz for MID TERM Exam Solved

Computer Number Systems

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Numbers and Arithmetic

3. Complete the following table of equivalent values. Use binary numbers with a sign bit and 7 bits for the value

1 Computing System 2. 2 Data Representation Number Systems 22

Why digital? Overview. Number Systems. Binary to Decimal conversion

CSCI 255. S i g n e d N u m s / S h i f t i n g / A r i t h m e t i c O p s.

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

ECE260: Fundamentals of Computer Engineering

Multiplication of signed-operands

Number System conversions

Combinational Logic Design Arithmetic Functions and Circuits

Computer Architecture, IFE CS and T&CS, 4 th sem. Representation of Integer Numbers in Computer Systems

Unit II Chapter 4:- Digital Logic Contents 4.1 Introduction... 4

of Digital Electronics

CSE 241 Digital Systems Spring 2013

COMBINATIONAL LOGIC FUNCTIONS

Number Theory: Representations of Integers

CISC 1400 Discrete Structures

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

2. Associative Law: A binary operator * on a set S is said to be associated whenever (A*B)*C = A*(B*C) for all A,B,C S.

CPE100: Digital Logic Design I


Numbers and Arithmetic

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

Negative Bit Representation Outline

Discrete mathematics is the study of techniques, ideas and modes of

Ex code

Binary addition (1-bit) P Q Y = P + Q Comments Carry = Carry = Carry = Carry = 1 P Q

Number Representation and Waveform Quantization

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

CS 140 Lecture 14 Standard Combinational Modules

Informatics 1 - Computation & Logic: Tutorial 3

CHAPTER 7. Exercises 17/ / /2 2 0

You separate binary numbers into columns in a similar fashion. 2 5 = 32

0 / 1 Now, Binary value of the given number :-

Counting in Different Number Systems

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

Prepared by Sa diyya Hendrickson. Package Summary

Module 2. Basic Digital Building Blocks. Binary Arithmetic & Arithmetic Circuits Comparators, Decoders, Encoders, Multiplexors Flip-Flops

Number System. Decimal to binary Binary to Decimal Binary to octal Binary to hexadecimal Hexadecimal to binary Octal to binary

Carry Look Ahead Adders

Section 1.1: Patterns in Division

UNIVERSITI TENAGA NASIONAL. College of Information Technology

ABE Math Review Package

B. Converting Numbers in Base ten to other bases Example

2.5 정수와알고리즘 (Integers and Algorithms)

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Base-b representations of integers. (b 진법표현 ) Algorithms for computer arithmetic: Euclidean algorithm for finding GCD s.

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

Chapter 1. Binary Systems 1-1. Outline. ! Introductions. ! Number Base Conversions. ! Binary Arithmetic. ! Binary Codes. ! Binary Elements 1-2

THE TEACHER UNDERSTANDS THE REAL NUMBER SYSTEM AND ITS STRUCTURE, OPERATIONS, ALGORITHMS, AND REPRESENTATIONS

CSE 1400 Applied Discrete Mathematics Definitions

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

Chapter 4 Number Representations

Math Review. for the Quantitative Reasoning measure of the GRE General Test

Lecture 2 Review on Digital Logic (Part 1)

Fundamentals of Mathematics I

2 ways to write the same number: 6,500: standard form 6.5 x 10 3 : scientific notation

Park Forest Math Team. Meet #3. Number Theory. Self-study Packet

CSE 20 Discrete Math. Algebraic Rules for Propositional Formulas. Summer, July 11 (Day 2) Number Systems/Computer Arithmetic Predicate Logic

ELEN Electronique numérique

EE 109 Final Don t Make the Same Mistake

Adders, subtractors comparators, multipliers and other ALU elements

Digital Systems and Information Part II

Transcription:

Numbering Systems Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary. Addition & Subtraction using Octal & Hexadecimal 2 s Complement, Subtraction Using 2 s Complement.

Objectives Understand the binary number system and decimal number system Be able to convert from binary to decimal Be able to convert from decimal to binary Be able to make binary addition Understand 2 s complement and Subtraction using 2 s complement

Binary & Decimal Systems

Bits & Bytes Bits are binary digits; they are either 0s or 1s. Bit (b) Binary digit, a 1 or 0 Computers operate with electronic switches that are either "on" or "off", corresponding to 1 or 0. A byte is a group of eight bits Byte (B) 8 bits

Decimal System Since we use only 10 digits in our daily calculations, our system of representing numbers is called Decimal System. So the numerical value Eight thousands nine hundred fifty four is represented as: 8 9 5 4 = 8*10 3 + 9*10 2 + 5*10 1 + 4*10 0

Decimal number system Base 10 because it uses ten symbols 0,1,2,3,4,5,6,7,8,9 2134 could also be written as: (2x10 3 ) + (1x10 2 ) + (3x10 1 ) + (4x10 0 )

Binary System Since a computer is a machine that can only work on two states: ON or OFF or two electrical pulse states High or Low, or two logical states True or False or simply 1 or 0 So the alphabet in computers is only formed of two entities (rather than 10 in the decimal system). That is why it is called Binary System.

Binary number system Base 2 because it uses 2 symbols 0 & 1 Computers recognize and process data using the binary (Base 2) numbering system The position, or place, of each digit represents the number 2 the base number raised to a power (exponent), based on its position (2 0, 2 1, 2 2, etc.) 10110 = (1 x 2 4 = 16) + (0 x 2 3 = 0) + (1 x 2 2 =4) + (1 x 2 1 = 2) + (0 x 2 0 = 0) = 22

Binary System Numerical Values in Binary System are represented as a combination of 1 s and 0 s, For example Decimal Binary 0 0 1 1 2 10 3 11 4 100.. 8 1000 9 1001 etc..

Binary System Notice the Following: Decimal Binary 3 = 3*10 0 11 = 1*2 1 + 1*2 0 10 = 1*10 1 + 0*10 0 1010 = 1*2 3 +0*2 2 +1*2 1 +0*2 0 So what is the decimal value of this binary number: 1 0 0 1 0 1?

Converting From Binary Decimal Decimal Binary

Converting from binary to decimal Multiply the binary digits by the base number (2), raised to the exponent of its position starting at 0. Binary no. 1 0 0 1 0 1 0 Position 6 5 4 3 2 1 0 2^posn. 2^6 2^5 2^4 2^3 2^2 2^1 2^0 Answer: 1*2^6+0*2^5+0*2^4+1*2^3+0*2^2+1*2^1+0*2^0 = 64 + 0 + 0 + 8 + 0 + 2 + 0 = 74

Binary Fractions The decimal value is calculated in the same way as for non-fractional numbers, the exponents are now negative.

Example: 101.001 (binary) =1* 2 2 + 0* 2 1 + 1* 2 0 + 0* 2-1 + 0* 2-2 + 1 x 2-3 = 4 +0 + 1 + 0 + 0 + 1 5 8 = = 5.125 (decimal) Note: 1 2 2-1 = = 0.5 1 4 2-2 = = 0.25 1 2-3 = 8 = 0.125 1 8 2-4 1 = = 0.0625 etc. 16

Try these Binary Decimal equivalent 0011? 01000010? 1111? 0101.01? 11.11? 01010.1101?

Converting from decimal to binary Divide the decimal number by two. Note the result & remainder. Repeat the process until the result is zero. The binary number equivalent is got reading all the remainders in the reverse order to which they were got.

Converting from decimal to binary E.g. decimal 46 46/2 = 23 rem 0 23/2 = 11 rem 1 11/2 = 5 rem 1 5/2 = 2 rem 1 2/2 = 1 rem 0 1/2 = 0 rem 1 Binary number is: 101110

converting decimal to binary fractions Consider left and right of the decimal point separately. The stuff to the left can be converted to binary as before. _

Example: Give 27.6875 (base 10) in base 2 27 (base 10) to binary (base 2): 27/2 = 13 rem 1 13/2 = 6 rem 1 6/2 = 3 rem 0 3/2 = 1 rem 1 1/2 = 0 rem 1 27 (base 10) = 11011 (base 2)

Cont. Example.6875 (base 10) to binary (base 2): Integer Fraction Coefficient 0.6875 *2 = 1 + 0.3750 1 0.3750 *2 = 0 + 0.7500 0 0.7500 *2 = 1 + 0.5000 1 0.5000 *2 = 1 + 0.0000 1 0.6875 (base 10) =.1011 (base 2) So, 27.6875 (base 10) = 11011.1011 (base 2)

Try these: Decimal Binary equivalent 34? 67.44? 234? 56.678? 25? 102.75?

Binary Addition& Subtraction

Binary addition The binary addition table: 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0 (carry 1) Overflow: If there is not enough room to hold the result correctly.

Binary subtraction The binary subtraction table: 0-0 = 0 1-0 = 1 1-1 = 0 0-1 = 1 (borrow 1)

Binary Addition Add Two binary numbers 0101 (5 base 10) and 0011 (3 base 10) 0 1 0 1 5 + 0 0 1 1 + 3 1 0 0 0 8

Binary Addition 1 1 1 1 1 1 0 1 1 1 + 0 1 1 1 0 0 2 3 2 2-2 2 2 2 1 0 1 0 0 1 1 Verification 55 10 + 28 10 83 10 64 32 16 8 4 2 1 1 0 1 0 0 1 1 = 64 + 16 + 2 +1 = 83 10

Binary Addition ex 1 0 0 1 1 1 + 0 1 0 1 1 0 + Verification 128 64 32 16 8 4 2 1 = =

Binary Addition & Subtraction Accomplished exactly the same as decimal Only two values per position (0 or 1) Examples: Addition Subtraction Carry 1 1 1 1 1 0 1 0 0 1 1 1 + 0 1 0 0 1 0 1 1 1 1 1 1 0 0 1 0 Borrow 1 1 1 1 0 1 0 0 1 1 1-0 1 0 0 1 0 1 1 0 1 0 1 1 1 0 0

Binary Addition & Subtraction Exercise Add the following two binary numbers 0 1 1 1 1 0 0 1 + 1 0 0 1 0 1 0 1 Subtract the following two numbers 1 1 0 0 0 1 0 1-0 0 1 0 1 0 0 1

Binary Multiplication& Division

Binary Multiplication Each bit from 2 nd number is multiplied by each bit in first number, then the result is added in order after shifting 1position each time. 0*0=0 0*1=0 1*0=0 1*1=1

Binary Multiplication Example 100110 (38) 1110 (14) 000000 100110 100110 + 100110 1000010100 (532)

Binary Division Using long division like decimal division 1 1.1 10 1 1 1 1 0 1 1 1 0 1 0 1 0 0 0

Octal Addition& Subtraction

Octal Addition Just as with decimal addition, octal uses carry when the sum of the values of a position exceeds 7 10 [or 7 8 ] Carry 1 1 1 1 2 3 4 + 5 6 7 2 02 3

Octal Addition 1 1 6 4 3 7 8 + 2 5 1 0 8 9 9-8 8 (subtract Base (8)) 1 1 1 4 7 8

Octal Addition ex 3 5 3 6 8 + 2 4 5 7 8 - (subtract Base (8))

Octal Subtraction Just as with decimal subtraction, Octal uses borrow when the difference between the values of a position requires it Borrow 1 256-137 117

Octal Subtraction 8 0 0 8 1 1 1 4 7 8 8 9-6 4 3 7 8 2 5 1 0 8

Octal Subtraction ex 3 5 3 6 8-2 4 5 7 8

Hexadecimal Addition& Subtraction

Hexadecimal Addition Just as with decimal addition, hexadecimal uses carry when the sum of the values of a position exceeds 15 10 [or F 16 ] Carry 1 1 1 5 6 7 8 1 2 3 4 + 8 A 1 1 D E F 0 E 0 8 9 F 1 2 4 H Note that FFFFH may be treated as -1 depending on whether we are dealing with signed or unsigned values

Hexadecimal Addition 1 1 7 C 3 9 16 + 3 7 F 2 16 20 18 11-16 16 (subtract Base (16)) B 4 2 B 16

Hexadecimal Addition 8 A D 4 16 + 5 D 6 16 - (subtract Base (16)) 16

Hexadecimal Subtraction Just as with decimal subtraction, hexadecimal uses borrow when the difference between the values of a position requires it Borrow 1 1 1 8 A 1 1 D E F 0-5 6 7 8 1 2 3 4 3 3 9 9 C C B 4 H

Hexadecimal Subtraction B 16 7 C 3 9 16 19-3 7 F 2 16 4 4 4 7 16

Hexadecimal Subtraction 8 A D 4 16-5 D 6 16 16

2 s Complement & Subtraction using 2 s Complement

How To Represent Signed Numbers Plus and minus sign used for decimal numbers: 25 (or +25), -16, etc. For computers, desirable to represent everything as bits. Three types of signed binary number representations: signed magnitude, 1 s complement, 2 s complement. In each case: left-most bit indicates sign: positive (0) or negative (1). Consider signed magnitude: 00001100 2 = 12 10 10001100 2 = -12 10 Sign bit Magnitude Sign bit Magnitude

One s Complement Representation The one s complement of a binary number involves inverting all bits. 1 s comp of 00110011 is 11001100 1 s comp of 10101010 is 01010101 00001100 2 = 12 10 11110011 2 = -12 10 Sign bit Magnitude Sign bit Magnitude

Two s Complement Representation The two s complement of a binary number involves inverting all bits and adding 1. 2 s comp of 00110011 is 11001101 2 s comp of 10101010 is 01010110 To find negative of 2 s complement number take the 2 s complement. 00001100 2 = 12 10 11110100 2 = -12 10 Sign bit Magnitude Sign bit Magnitude

Two s Complement Shortcuts Algorithm Simply complement each bit and then add 1 to the result. Finding the 2 s complement of (01100101) 2 and of its 2 s complement N = 01100101 [N] =10011011 10011010 01100100 + 1 + 1 ------------- ------------- 10011011 01100101

1 s Complement Addition Using 1 s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100) 2 and +(0001) 2. Let s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1 s comp. (1) 10 = +(0001) 2 = 00001 2 in 1 s comp. Step 1: Add binary numbers Step 2: Add carry to low-order bit 0 1 1 0 0 Add + 0 0 0 0 1 -------------- 0 0 1 1 0 1 Add carry 0 -------------- Final Result 0 1 1 0 1

1 s Complement Subtraction Using 1 s complement numbers, subtracting numbers is also easy. For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. Let s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1 s comp. (-1) 10 = -(0001) 2 = 11110 2 in 1 s comp. 1 s comp Step 1: Take 1 s complement of 2 nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit Add 0 1 1 0 0-0 0 0 0 1 -------------- 0 1 1 0 0 + 1 1 1 1 0 -------------- 1 0 1 0 1 0 Add carry 1 -------------- Final Result 0 1 0 1 1

2 s Complement Addition Using 2 s complement numbers, adding numbers is easy. For example, suppose we wish to add +(1100) 2 and +(0001) 2. Let s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2 s comp. (1) 10 = +(0001) 2 = 00001 2 in 2 s comp. Step 1: Add binary numbers Step 2: Ignore carry bit Add Final Result 0 1 1 0 0 + 0 0 0 0 1 -------------- 0 0 1 1 0 1 Ignore

2 s Complement Subtraction Using 2 s complement numbers, follow steps for subtraction For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. Let s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2 s comp. (-1) 10 = -(0001) 2 = 11111 2 in 2 s comp. 2 s comp Step 1: Take 2 s complement of 2 nd operand Step 2: Add binary numbers Step 3: Ignore carry bit Add Final Result 0 1 1 0 0-0 0 0 0 1 -------------- 0 1 1 0 0 + 1 1 1 1 1 -------------- 1 0 1 0 1 1 Ignore Carry

2 s Complement Subtraction: Example #2 Let s compute (13) 10 (5) 10. (13) 10 = +(1101) 2 = (01101) 2 (-5) 10 = -(0101) 2 = (11011) 2 Adding these two 5-bit codes carry Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000) 2 = +(1000) 2 = +(8) 10. 0 1 1 0 1 + 1 1 0 1 1 -------------- 1 0 1 0 0 0

2 s Complement Subtraction: Example #3 Let s compute (5) 10 (12) 10. (-12) 10 = -(1100) 2 = (10100) 2 (5) 10 = +(0101) 2 = (00101) 2 Adding these two 5-bit codes 0 0 1 0 1 + 1 0 1 0 0 -------------- 1 1 0 0 1 Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001) 2 = -(7) 10.

Thank You