200 likes | 334 Views
Digital Design: From Gates to Intelligent Machines. Bruce F Katz Da Vinci Engineering Press. Number Systems. Numbers and Numerals A number is a quantity A numeral is a representation of a number Example (all representations of the quantity 5)
E N D
Digital Design:From Gates to Intelligent Machines Bruce F Katz Da Vinci Engineering Press
Number Systems Numbers and Numerals A number is a quantity A numeral is a representation of a number Example (all representations of the quantity 5) 5, V (Roman), 101 (binary), (Babylonian) Not equivalent in ease of computation, however
Number Systems Positional Number Systems A quantity is a weighted sum of powers of a base b Compactness of representation and ease of computation Additional characteristics digits to the left of radix point are integral digits to the right of the radix point are fractional
Number Systems Examples of Positional Number Systems base 10 102410 = 1*103 + 0*102 + 2*101 + 4*100 base 8 417.238= 4*82 + 1*81 + 7*80 + 2*8-1 + 3*8-2 = 256 + 8 + 7 + 2/8 + 3/64 base 2 1010.1 = 1*23 + 1*21 + 1*2-1 = 10.510
Number Systems Commonly used bases
Number Systems Which base is best for human use? Base 12 has the most divisors among the small numbers but we usually use base 10. Why?
Number Systems Conversion between bases (special case) Principle If one base is an integer power of another base, can group by this integer to perform conversion. Examples 1011112 = ?8 solution: group by 3 bits {101}{111}2 = 578 F416 = ?2 solution: each hex digit represents 4 bits F416 = {1111}{0100}2 = 111101002
Number Systems Conversion to and from base 10 To base 10 Use definition of a positional number Example: 1101.1012 to base 10 1101.1012 = 1*23 + 1*22 + 0*21 + 1*21 + 1*2-1 + 0*2-2 + 1*2-3 = 13.625 From base 10 Use reformulation of definition of a positional number Successive divisions by the base will yield then digits as remainders Example: 125 to base 3 125/3 = 41 remainder 2 41/3 = 13 remainder 2 13/3 = 4 remainder 1 4/3 = 1 remainder 1 1/3 = 0 remainder 1 therefore answer is 111223
Number Systems Binary Number Systems Motivation Correspondence between 0 and 1 and logical values (true and false) Ease of constructing binary circuits Powers of 2
Number Systems Binary Addition and Subtraction Addition Same as decimal addition with binary carries 0 0 1 1 0 0 1 0 carry 1 0 0 1 1 1 0 1 addend1 0 1 0 1 1 0 0 1 addend2 ----------------------- 1 1 1 1 0 1 1 0 sum Subtraction Same as decimal subtraction with binary borrows 0 1 0 0 0 1 1 0 borrow 1 1 0 1 1 1 0 0 minuend 0 1 1 0 1 0 0 1 subtrahend ----------------------- 0 1 1 1 0 0 1 1 difference
Number Systems Binary Addition and Subtraction Tables Important:These tables are the foundation for computer arithmetic!
Number Systems Binary Multiplication Easier than decimal multiplication because always multiplying by 0 or 1 Example 0 1 1 0 * 1 0 1 1 ---------- 0 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 ------------------- 1 0 0 0 0 1 0
Number Systems Representing Negative Numbers System 1: Signed Magnitude Leftmost bit represents negative sign Examples 01010111 = 87 11010111 = - 87 Advantage Simplicity Disadvantage Mathematical operations clumsy, e.g. addition: if (signs same)then { add magnitudes give result this sign } else /* signs different */ { compare magnitudes subtract smaller from larger give result sign of the larger }
Number Systems Representing Negative Numbers System 2: 2’s complement Positive numbers identical, negative numbers 2n - positive version, where n is the number of bits in the representation Examples 00010001 = 17 100000000 - 00010001 = 11101111 = - 17 Trick for computing negative number Flip all the bits and add 1 00010001 11101110 after flip 11101111 after adding 1 Note: Negative numbers will always begin with 1, positive with 0
Number Systems Representing Negative Numbers System 2: 2’s complement Addition method Just add! (and ignore any bits > 2n-1) 0 0 1 0 1 0 1 1 (43) +1 1 1 0 1 1 1 1(-17) ------------------- 1 0 0 0 1 1 0 1 0 Overflow condition: If add 2 positive and get a negative or vice versa Example 1 0 0 0 1 1 1 1 (-113) +1 1 1 0 1 1 1 1(-17) ------------------- 1 0 1 1 1 1 1 1 0 overflow!
Number Systems Codes A way of representing a set of quantities or a set of symbols within a given base Example in base 2
Number Systems Codes BCD Each decimal digit is encoded by four binary digits Motivation ease of conversion Examples 0001 0100 14 1001 0111 97 Gray Coding Each successive number differs by only 1 bit from previous Motivation counting with CMOS Karnaugh maps
Number Systems Codes Parity An extra bit is added to make the string always even or odd Motivation error checking ASCII
Number Systems Codes Unicode 4 hex digits encode 216 characters Example
Number Systems Summary of topics Numbers and numerals Positional number systems Conversion between bases Binary number systems Binary addition, subtraction, and multiplication Representation of negative numbers Codes