Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

ICS312 Set 2 Representation of Numbers and Characters.
Representing Numbers: Integers
COE 202: Digital Logic Design Signed Numbers
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Standard positional representation of numbers:
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
ECE 301 – Digital Electronics Number Systems and Conversion, Binary Arithmetic, and Representation of Negative Numbers (Lecture #10) The slides included.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are 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
COE 202: Digital Logic Design Number Systems Part 1
Number Systems Lecture 02.
Number Systems Computer Science 210 Computer Organization.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
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 :
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Number Representations and Computer Arithmetic. CS 21a 9/23/02 Odds and Ends Slide 2 © Luis F. G. Sarmenta and John Paul Vergara, Ateneo de Manila University.
Numbering systems.
Data Representation – Binary Numbers
Numbering Systems CS208.
Number Systems and Logic UCT Dept of Computer Science CSC
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
ECE 331 – Digital System Design
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
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.
Positional Number Systems
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Number Systems and Logic UCT Dept of Computer Science CS115 ~ 2003.
AEEE2031 Data Representation and Numbering Systems.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
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=
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
NUMBER SYSTEMS.
Assoc. Prof. Dr. Ahmet Turan ÖZCERİT.  The base of numbers  Conversion between number bases  Arithmetic operations on different bases You will learn:
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
Chapter 1: Binary Systems
IT1004: Data Representation and Organization Negative number representation.
CPEN Digital Logic Design Binary Systems Spring 2004 C. Gerousis © Digital Design 3 rd Ed., Mano Prentice Hall.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Memory unit terminology memory contains series of bits, grouped into addressable units word - unit of memory access and/or size of data registers, 16/32/64.
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.
CS2100 Computer Organisation
Cosc 2150: Computer Organization
NUMBER SYSTEMS.
Chapter 3 Data Representation
University of Gujrat Department of Computer Science
Data Representation in Computer Systems
Numbering System TODAY AND TOMORROW 11th Edition
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Digital Electronics and Microprocessors
Decimal and binary representation systems
Presentation transcript:

Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)

Counting…. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, … What comes next? Why do we have ten digits?

Number Representations We are used to base/radix 10 (decimal) 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 10, 20, 30, …, , …, 100, …, 1000, …,

Decimal Example: : Represents: Decimal 1* * *10 + 1*1 + 2/10 + 0/ /

Number Representations General radix r number, N r Represents: d p d p-1 … d 2 d 1 d 0. d –1 d –2 … d –q r p r p-1 … r 2 r 1 r 0 r -1 r -2 … r -q d p r p + d p-1 r p-1 + …+ d 2 r 2 + d 1 r 1 + d 0 r 0 + d –1 r d –2 r --2 +…d –q r -q

Binary Computer uses presence/absence of voltage Digits 0 and 1(off/on). i.e. base 2 Bit = B inary dig it

Binary Binary Example: : Represents: 1*8 + 0*4 + 0*2 + 1*1 + 1/2 + 0/4 + 1/8 =

Binary Integers (whole numbers) stored in n-bit words n-bit binary number has range: 0 to (2 n -1) Largest 8-bit number: = = = = =255 10

Binary to Decimal Conversion 1.quot = number; i = 0; 2.repeat until quot = 0: 1.quot = quot/2; 2.digit i = remainder; 3.i++; gives digits from least to most significant bit Example: 33/2 = 16 rem 1(lsb) 16/2 = 8 rem 0 8/2 = 4 rem 0 4/2 = 2 rem 0 2/2 = 1 rem 0 1/2 = 0 rem 1(msb) => =

Converting fractional numbers Convert int and frac. parts separately i = 0; repeat until N = 1.0 or i = n: N = FracPart(N); N *= 2; digit i = IntPart(N); i++ Example: *2 = int = 1 (msb) *2 = int = *2 = int = *2 = int = 1 (lsb) => = Caution: Many numbers cannot be represented accurately: = 0.0[1001]... 2 (bracket repeats, limited by bit size)

Binary Addition Adding binary numbers: = = = = 0 carry 1 Add to : ____________

Binary Addition Adding binary numbers: = = 1; = 0; = 0 carry 1 Add to : Check it!

Binary Addition: Overflow Possibility of overflow Add 2 10 to : [1] = We only have 8 bits to store answer...so it's zero!

Binary Addition: Overflow Overflow: what happens? Program can generate an “exception” to let us know Usually many bits used (e.g. Intel word is 32-bits) so occurrence is reduced

Signed Numbers So far, only have positive numbers What about negative numbers? What about subtraction?

Signed Numbers Can use left-most bit to encode sign 0 -> pos, 1 -> neg

Signed Numbers For 8-bits, range is: Problems: –Two zeros!! –Addition not straight forward –Must check sign-bit before adding (bad for hardware implementors) This is non-sensical and wasteful: can use extra bit pattern -(2 7 -1) +(2 7 -1)

One’s Complement Try “one's complement”: –negative numbers obtained by flipping bits –positive numbers unchanged –Example: Left-most bit still indicates sign

Subtraction with One’s complement Now easy to subtract: complement number and add: = complement ( ) = = = complement ( ) = (-1)

Subtraction with One’s complement Caution: If overflow, –if numbers have different signs, carry is added into lsb –if numbers have same sign, actual overflow has occured

Subtraction with One’s complement Evaluate 10–7 using 8-bit one’s complement arithmetic:

Subtraction with One’s complement Evaluate 10–7 using 8-bit one’s complement arithmetic: = complement ( ) = = carry 1 = = = 3 10

Two’s Complement Still have two zeros  two’s complement –Complement then add 1 –Our number range now asymmetric: -2 7 to –Used extra zero bit pattern

Two’s Complement Now when we add, discard carry = complement ( ) = = carry 1 (discard) = 3 Same overflow test can be used (same/different signs)

Octal and Hexadecimal Base 8 (octal) and base 16 (Hexadecimal) are sometimes used (powers of 2) Octal uses 8 digits (0-7) Hex uses 16 “digits”: 0, 1, 2, 3, 4, 5, 6, 7,8, 9, A, B, C, D, E, F

Octal and Hexadecimal Each octal digit represents 3-bits Each hex digit represents 4-bits Examples: = = (001)(101) 2 = 15 8 = (1101) 2 = D 16

Octal and Hexadecimal Conversion from decimal as for bin: –divide/multiply by 8 or 16 instead –May be easier to convert to binary first Binary to octal or hexadecimal –group bits into 3 (octal) or 4 (hex) from LS bit –pad with leading zeros if required

Octal and Hexadecimal: Example

Octal and Hexadecimal: Example = (000) (100) (011) (011) (010) (111) = = (0100) (0110) (1101) (0111) = 46D7 16 Note padding at front of number

Octal and Hexadecimal To convert from hex/octal to binary: reverse procedure FF 16 = (1111)(1111) = (011)(111)(111) 2 NOTE: for fractional conversion, move from left to right and pad at right end: = 0. (110) (011) (010) (110) = = 0.(110) 2 = Convert fractional/integer part separately