Four Important Number Systems

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

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

Conversions between Decimal and Binary

ECE380 Digital Logic. Positional representation

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

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

ECE260: Fundamentals of Computer Engineering

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

ENGIN 112 Intro to Electrical and Computer Engineering

CHAPTER 2 NUMBER SYSTEMS

NUMBERS AND CODES CHAPTER Numbers

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

CISC 1400 Discrete Structures

Week No. 06: Numbering Systems

CSE 241 Digital Systems Spring 2013

Numbers. Dr Hammadi Nait-Charif. Senior Lecturer Bournemouth University United Kingdom

Chapter 1 CSCI

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Binary addition example worked out

Fundamentals of Digital Design

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

Multiplication of signed-operands

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

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

Numbers and Arithmetic

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

CSEN102 Introduction to Computer Science

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

Number Theory: Representations of Integers

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

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

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.

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

A crash course in Digital Logic

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

Counting in Different Number Systems

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

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

Chapter 9 - Number Systems

Number System conversions

ENG2410 Digital Design Introduction to Digital Systems. Fall 2017 S. Areibi School of Engineering University of Guelph

Complement Arithmetic

of Digital Electronics

CPE100: Digital Logic Design I

UNIVERSITI TENAGA NASIONAL. College of Information Technology

ECE 372 Microcontroller Design

ENGIN 112 Intro to Electrical and Computer Engineering

Numbers and Arithmetic

COT 3100 Applications of Discrete Structures Dr. Michael P. Frank

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

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

hexadecimal-to-decimal conversion

Introduction to digital systems. Juan P Bello

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

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Math 230 Assembly Language Programming (Computer Organization) Numeric Data Lecture 2

CS1800 Discrete Structures Fall 2017 October, CS1800 Discrete Structures Midterm Version A

Lecture 5: Arithmetic

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

Informatics 1 - Computation & Logic: Tutorial 3

Number Representation and Waveform Quantization

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

1 Computing System 2. 2 Data Representation Number Systems 22

Computer Number Systems

What is Binary? Digital Systems and Information Representation. An Example. Physical Representation. Boolean Algebra

3 The fundamentals: Algorithms, the integers, and matrices

Chapter 4 Number Representations

Lecture 2 Review on Digital Logic (Part 1)

ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN. Week 2 Dr. Srinivas Shakkottai Dept. of Electrical and Computer Engineering

Schedule. ECEN 301 Discussion #25 Final Review 1. Date Day Class No. 1 Dec Mon 25 Final Review. Title Chapters HW Due date. Lab Due date.

Additive Numbering Systems and Numbers of Different Bases MAT 142 RSCC Scott Surgent

FYSE410 DIGITAL ELECTRONICS [1] [2] [3] [4] [5] A number system consists of an ordered set of symbols (digits).

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

CA Compiler Construction

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

Mark Redekopp, All rights reserved. Lecture 1 Slides. Intro Number Systems Logic Functions

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

4 Number Theory and Cryptography

Number Systems. There are 10 kinds of people those that understand binary, those that don t, and those that expected this joke to be in base 2

ALU (3) - Division Algorithms

CS1800 Discrete Structures Final Version A

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

Binary Multipliers. Reading: Study Chapter 3. The key trick of multiplication is memorizing a digit-to-digit table Everything else was just adding

NUMBER SYSTEMS. and DATA REPRESENTATION. for COMPUTERS (PROBLEM ANSWERS)

SAU1A FUNDAMENTALS OF DIGITAL COMPUTERS

Discrete Mathematics GCD, LCM, RSA Algorithm

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

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

CS1800: Hex & Logic. Professor Kevin Gold

Combinational Logic. By : Ali Mustafa

Midterm Examination # 1 Wednesday, February 25, Duration of examination: 75 minutes

SAMPLE ANSWERS MARKER COPY

DSP Design Lecture 2. Fredrik Edman.

What s the Deal? MULTIPLICATION. Time to multiply

Number Representations

LABORATORY MANUAL MICROPROCESSOR AND MICROCONTROLLER

CSE 20 DISCRETE MATH. Fall

CSE 20: Discrete Mathematics

Logic Theory in Designing of Digital Circuit & Microprocessor

Binary logic consists of binary variables and logical operations. The variables are

Transcription:

Four Important Number Systems System Why? Remarks Decimal Base 10: (10 fingers) Most used system Binary Base 2: On/Off systems 3-4 times more digits than decimal Octal Base 8: Shorthand notation for working with binary 3 times less digits than binary Hex Base 16 4 times less digits than binary Chapter 2 Instructions: Language of the Computer 34

Positional Number Systems Have a radix r (base) associated with them. In the decimal system, r = 10: Ten symbols: 0, 1, 2,..., 8, and 9 More than 9 move to next position, so each position is power of 10 Nothing special about base 10 (used because we have 10 fingers) What does 642.391 10 mean? 6 x 10 2 + 4 x 10 1 + 2 x 10 0. 3 x 10-1 + 9 x 10-2 + 1 x 10-3 Increasingly +ve powers of radix Radix point Increasingly -ve powers of radix Chapter 2 Instructions: Language of the Computer 35

Positional Number Systems(2) What does 642.391 10 mean? Radix point Base 10 10 2 10 1 10 0 10-1 10-2 10-3 (r) (100) (10) (1) (0.1) (0.01) (0.001) Coefficient 6 4 2 3 9 1 (a j ) Product: a j *r i 600 40 2 0.3 0.09 0.001 Value = 600 + 40 + 2 + 0.3 + 0.09 + 0.001 = 642.391 Multiply each digit by appropriate power of 10 and add them together -m In general: i a i r i=n-1 Chapter 2 Instructions: Language of the Computer 36

Positional Number Systems(3) Number system Radix Symbols Binary 2 {0,1} Octal 8 {0,1,2,3,4,5,6,7} Decimal 10 {0,1,2,3,4,5,6,7,8,9} Hexadecimal 16 {0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f} Chapter 2 Instructions: Language of the Computer 37

Binary Number System Decimal Binary Decimal Binary 0 0000 8 1000 1 0001 9 1001 2 0010 10 1010 3 0011 11 1011 4 0100 12 1100 5 0101 13 1101 6 0110 14 1110 7 0111 15 1111 Chapter 2 Instructions: Language of the Computer 38

Octal Number System Decimal Octal Decimal Octal 0 0 8 10 1 1 9 11 2 2 10 12 3 3 11 13 4 4 12 14 5 5 13 15 6 6 14 16 7 7 15 17 Chapter 2 Instructions: Language of the Computer 39

Hexadecimal Number System Decimal Hex Decimal Hex 0 0 8 8 1 1 9 9 2 2 10 A 3 3 11 B 4 4 12 C 5 5 13 D 6 6 14 E 7 7 15 F Chapter 2 Instructions: Language of the Computer 40

Four Number Systems Decimal Binary Octal Hex Decimal Binary Octal Hex 0 0000 0 0 8 1000 10 8 1 0001 1 1 9 1001 11 9 2 0010 2 2 10 1010 12 A 3 0011 3 3 11 1011 13 B 4 0100 4 4 12 1100 14 C 5 0101 5 5 13 1101 15 D 6 0110 6 6 14 1110 16 E 7 0111 7 7 15 1111 17 F Chapter 2 Instructions: Language of the Computer 41

Conversion: Binary to Decimal Binary Decimal 1101.011 2 (??) 10 r 2 3 (8) 2 2 (4) 2 1 (2) 2 0 (1) 2-1 (0.5) 2-2 (0.25) 2-3 (0.125) a j 1 1 0 1 0 1 1 a j *r 8 4 0 1 0 0.25 0.125 (1101.011) 2 = 8 + 4 + 1 + 0.25 + 0.125 = 13.375 1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 1 x 2 0. 0 x 2-1 + 1 x 2-2 + 1 x 2-3 = 13.375 10 Binary point Chapter 2 Instructions: Language of the Computer 42

Conversion: Decimal to Binary A decimal number can be converted to binary by repeated division by 2 if it is an integer number 2 Remainder 155 77 1 Least Significant Bit (LSB) 77 38 1 38 19 0 19 9 1 9 4 1 4 2 0 2 1 0 1 0 1 Most Significant Bit (MSB) Arrange remainders in reverse order 155 10 = 10011011 2 Chapter 2 Instructions: Language of the Computer 43

Conversion: Decimal to Binary If the number includes a radix point, it is necessary to separate the number into an integer part and a fraction part, each part must be converted differently. Decimal (27.375) 10 Binary (??) 2 number 2 Remainder 27 13 1 13 6 1 6 3 0 3 1 1 1 0 1 Arrange remainders in reverse order: 11011 27.375 10 =11011.011 2 number x2 Integer 0.375 0.75 0 0.75 1.50 1 0.50 1.0 1 Arrange in order: 011 Chapter 2 Instructions: Language of the Computer 44

Conversion: Octal to Binary Octal Binary 345.5602 8 (???) 2 3 4 5. 5 6 0 2 011 100 101 101 110 000 010 345.5602 8 =11100101.10111000001 2 Chapter 2 Instructions: Language of the Computer 45

Conversion: Binary to Octal Binary Octal 11001110.0101101 2 (??) 8 Note trailing zeros 011 0 011 10 3 1 6 Group by 3 s Add leading zeros if necessary. 0 101 101 00 2 6 4 Group by 3 s Add trailing zeros if necessary 11001110.0101101 2 = 316.264 8 Chapter 2 Instructions: Language of the Computer 46

Conversion: Binary to Hex Binary Hex 11100101101.1111010111 2 (??) 16 Note trailing zeros 01110 0101 101 7 2 D. 1 1110 1011 100 C F 5 Group by 4 s Add leading zeros if necessary Group by 4 s Add trailing zeros if necessary = 72D.F5C 16 Chapter 2 Instructions: Language of the Computer 47

Conversion: Hex to Binary Hex B9A4.E6C 16 Binary (??) 2 1 0111 0011 0100 100 B 9 A 4. 1 1100 1101 100 E 6 C 1011100110100100.1110011011 2 Chapter 2 Instructions: Language of the Computer 48

Conversion: Hex to Decimal Hex B63.4C 16 Decimal (??) 10 16 2 16 1 16 0 16-1 16-2 B (=11) 6 3 4 C (=12) = 2816 + 96 + 3 + 0.25 + 0.046875 = 2915.296875 11 16 2 +6 16 1 +3 16 0. 4 16 1 +12 16 2 =2915.296875 10 Chapter 2 Instructions: Language of the Computer 49

Conversion: Activity 1 Convert the hexadecimal number A59.FCE to binary Convert the decimal number 166.34 into binary Chapter 2 Instructions: Language of the Computer 50

Binary Numbers How many distinct numbers can be represented by n bits? No. of Distinct nos. bits 1 2 {0,1} 2 4 {00, 01, 10, 11} 3 8 {000, 001, 010, 011, 100, 101, 110, 111} n 2 n Number of permutations double with every extra bit 2 n unique numbers can be represented by n bits Chapter 2 Instructions: Language of the Computer 52

Number System and Computers Some tips Binary numbers often grouped in fours for easy reading 1 byte=8-bit, 1 word = 4-byte (32 bits) In computer programs (e.g. Verilog, C) by default decimal is assumed To represent other number bases use System Representation Example for 20 Hexadecimal 0x... 0x14 Binary 0b... 0b10100 Octal 0o (zero and O ) 0o24 Chapter 2 Instructions: Language of the Computer 53

Number System and Computers(2) Addresses often written in Hex Most compact representation Easy to understand given their hardware structure For a range 0x000 0xFFF, we can immediately see that 12 bits are needed, 4K locations Tip: 10 bits = 1K Chapter 2 Instructions: Language of the Computer 54

Negative Number Representation Three kinds of representations are common: 1. Signed Magnitude (SM) 2. One s Complement 3. Two s Complement Chapter 2 Instructions: Language of the Computer 55

Signed Magnitude Representation [0,1] {.} Sign bit (n -1) (left most) magnitude bits 0 indicates +ve 1 indicates -ve 8 bit representation for +13 is 0 0001101 8 bit representation for -13 is 1 0001101 Chapter 2 Instructions: Language of the Computer 56

1 s Complement Notation Let N be an n-bit number and Ñ(1) be the 1 s Complement of the number. Then, Ñ(1) = 2 n - 1 - N The idea is to leave positive numbers as is, but to represent negative numbers by the 1 s Complement of their magnitude. Example: Let n = 4. What is the 1 s Complement representation for +6 and -6? +6 is represented as 0110 (as usual in binary) -6 is represented by 1 s complement of its magnitude (6) Chapter 2 Instructions: Language of the Computer 57

1 s Complement Notation (2) 1 s C representation can be computed in 2 ways: Method 1: 1 s C representation of -6 is: 2 4-1 - N = (16 1 6) 10 = (9) 10 = (1001) 2 Method 2: For -6, the magnitude = 6 = (0110) 2 The 1 s C representation is obtained by complementing the bits of the magnitude: (1001) 2 Chapter 2 Instructions: Language of the Computer 58

2 s Complement Notation Let N be an n bit number and Ñ(2) be the 2 s Complement of the number. Then, Ñ(2) = 2 n - N Again, the idea is to leave positive numbers as is, but to represent negative numbers by the 2 s C of their magnitude. Example: Let n = 5. What is 2 s C representation for +11 and -13? +11 is represented as 01011 (as usual in binary) -13 is represented by 2 s complement of its magnitude (13) Chapter 2 Instructions: Language of the Computer 59

2 s Complement Notation (2) 2 s C representation can be computed in 2 ways: Method 1: 2 s C representation of -13 is 2 5 - N = (32 13) 10 = (19) 10 = (10011) 2 Method 2: For -13, the magnitude is 13 = (01101) 2 The 2 s C representation is obtained by adding 1 to the 1 s C of the magnitude 2 5 - N = (2 5 1 N ) + 1 = 1 s C + 1 01101 10010 10011 1 s C add 1 Chapter 2 Instructions: Language of the Computer 60

Comparing All Signed Notations 4-bit No. SM 1 s C 2 s C 0000 +0 +0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000-0 -7-8 1001-1 -6-7 1010-2 -5-6 1011-3 -4-5 1100-4 -3-4 1101-5 -2-3 1110-6 -1-2 1111-7 -0-1 In all 3 representations, a ve number has a 1 in MSB location To handle ve numbers using n bits, = 2 n-1 symbols can be used for positive numbers = 2 n-1 symbols can be used for negative umbers In 2 s C notation, only 1 combination used for 0 Chapter 2 Instructions: Language of the Computer 61

Unsigned Binary Integers Given an n-bit number x x 2 x 2 n 1 n 2 1 0 n 1 n 2 1 02 Range: 0 to +2 n 1 Example x 2 x 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0 2 2 +1 2 1 +1 2 0 = 0 + + 8 + 0 + 2 + 1 = 11 10 Using 32 bits 0 to +4,294,967,295 Chapter 2 Instructions: Language of the Computer 62

2 s-complement Signed Integers Given an n-bit number x x 2 x 2 n 1 n 2 1 0 n 1 n 2 1 02 x 2 x Range: 2 n 1 to +2 n 1 1 Example 1111 1111 1111 1111 1111 1111 1111 1100 2 = 1 2 31 + 1 2 30 + + 1 2 2 +0 2 1 +0 2 0 = 2,147,483,648 + 2,147,483,644 = 4 10 Using 32 bits 2,147,483,648 to +2,147,483,647 Chapter 2 Instructions: Language of the Computer 63

2 s-complement Signed Integers(2) Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers Non-negative numbers have the same unsigned and 2 s-complement representation Some specific numbers 0: 0000 0000 0000 1: 1111 1111 1111 Most-negative: 1000 0000 0000 Most-positive: 0111 1111 1111 Chapter 2 Instructions: Language of the Computer 64

Signed Negation Complement and add 1 Complement means 1 0, 0 1 x x 1111...1112 1 x 1 x Example: negate +2 +2 = 0000 0000 0010 2 2 = 1111 1111 1101 2 + 1 = 1111 1111 1110 2 Chapter 2 Instructions: Language of the Computer 65

Sign Extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left c.f. unsigned values: extend with 0s Examples: 8-bit to 16-bit +2: 0000 0010 => 0000 0000 0000 0010 2: 1111 1110 => 1111 1111 1111 1110 Chapter 2 Instructions: Language of the Computer 66