<<

Logical Bases: Representation of numbers most commonly used by humans are in base 10 and consist of the ten decimal digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. For example, the decimal 373 is 373 = 3*100 + 7*10 + 3

Positional describes the numbers according to position. For example, the two 3s in the decimal number 373 are in different positions, the 3 in the first position (at left) has a value which is 100 times more than the other 3. This notation can be described by a data flow diagram as follows at the left below.

Binary numbers are most commonly used in digital computing; they have base 2. The data flow diagram at the right shows the 1101 which is the decimal number 13. 1101 = 1*8 + 1*4 + 0*2 + 1*1 = 13 in decimal Decimal numbers (base 10) Binary numbers (base 2)

3 7 3 1 1 0 1 10 2

100 10 1 8 4 2 1

* * * * * * * 300 70 3 8 4 0 1 + +

373 13 1 Binary To add the ten decimal digits requires a table of 10*10 = 100 entries; but if the digits are binary a table of only 2*2 = 4 rows is needed. The binary add definition follows:

0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 2 = 10 = 0 with carry of 1

A table of such a simple (half adder) follows, showing the output of a sum s and a carry c. A logical gate diagram shows that the carry is simply the And of a, b. The sum is actually the exclusive-Or, which is formed in detail below. HA = Half Adder in out a b s c a | b & s 0 0 0 0 a ! 0 1 1 0 b 1 0 1 0 a & c 1 1 0 1 b carry

2 Longer Binary Addition Addition of two numbers, say A=3=11 and B=6=110 to yield a third D is done in stages. At each stage there is input a value a, and b, and a carry from the previous stage. Then there is an output of a sum s, and a carry to the next stage. This process begins with the least significant digits (at the right) and proceeds to the left. The previous Half Adders can be used as shown to create a Full Adder.

A = 3 = 0 0 1 1 FA = Full Adder

c a A HA B = 6 = 0 1 1 0 s b B c

0 1 1 0 Carry FA FA FA FA 0 c a 1 HA s b c D = 9 = 1 0 0 1

sum 3 General Numbers: to any base b In general, a number can be represented in any base b as shown. The base may be any ; the bases 2, 8, 10, 16 are most common. However, there may be unusual bases, negative values, , etc. The coefficients c0, c1, c2, .. are usually from some small set, usually 0, 1, 2, etc up to the value of the base.

General numbers (base b)

cn ... c2 c1 c0 b

bn b2 b1 b0

* * * *

+

cn*bn + .. + c2*b2 + c1*b1 + c0*b0

4 Numbers in base 3 Numbers in base 3 have the 3 coefficients, 0, 1 and 2. Some numbers, from 0 to 12, are shown in this base Note the beauty of this table; group them 3 at a time.

Ternary numbers (base 3) i base3 2 0 1 3 0 000 1 001 27 9 3 1 2 002 3 010 * * * * 4 011 5 012 6 020 + 7 021 8 022 9 100 Example: 10 101 2 1 0 11 102 (201)3 = 2*3 + 0*3 + 1*3 12 110 = 2*9 + 0*3 + 1*1 = 18 + 0 + 1 = 19

(201)3 = (19)10 5 Numbers in base 8 () Numbers in base 8 have the 8 coefficients, 0, 1, 2, .. 7. Some numbers, from 0 to 12 are shown in this base 8.

Octal numbers (base 8) i octal cn ... c2 c1 c0 8 0 0 1 1 512 64 8 1 2 2 3 3 * * * * 4 4 5 5 6 6 + 7 7 8 10 9 11 cn*8n + .. + c2*82 + c1*81 + c0*80 10 12 Example: 11 13 (201) = 2*82 + 0*81 + 1*80 8 12 14 = 2*64 + 0*8 + 1*1 = 128 + 0 + 1 = 129

(201)8 = (129)10 6 Numbers in base 16 () Numbers in base 16 have the 16 coefficients, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Some numbers, from 0 to 16 are shown in this base This hexadecimal base (called Hex) is very common in computing. Octal numbers (base 8) i hex cn ... c2 c1 c0 0 0 16 1 1 4096 256 16 1 2 2 3 3 4 4 * * * * 5 5 6 6 + 7 7 8 8 9 9 cn*16n + .. + c2*162 + c1*161 + c0*160 10 A Example: 11 B 2 1 0 (201)16 = 2*16 + 0*16 + 1*16 12 C = 2*256 + 0*16 + 1*1 13 D = 512 + 0 + 1 14 E = 513 15 F

(201)16 = (513)10 16 10 7 Numbers in base -2 Bases can be negative;the following one is binary base (-2). The coefficients are still binary, 0s and 1s only. Some numbers, both positive and negative are shown in this base This is not a common way to create negative numbers. Binary numbers (base -2)

cn ... c2 c1 c0 i base -2 i base -2 -2 0 0 0 0 1 1 -1 11 -8 4 -2 1 2 110 -2 10 3 111 -3 1101 * * * * 4 100 -4 1100 5 101 -5 1111 + 6 11010 -6 1110 7 11011 -7 1001 8 110000 -8 1000 cn*bn + .. + c2*b2 + c1*b1 + c0*b0

8 Numbers in base 2 (binary) with negative coefficients Bases can be positive with negative coefficients; The following one has a binary base 2 with coefficients 1, 0 and -1. The coefficient -1 can be written as 7, or as a 1 with a bar over it. Some numbers, both positive and negative are shown in this base This is also not a common way to create negative numbers.

Binary numbers (base 2) i base 2 i base 2 cn ... c2 c1 c0 0 0 0 0 2 1 1 -1 7 8 4 2 1 2 10 -2 70 3 11 -3 77 4 100 -4 700 * * * * 5 101 -5 707 6 110 -6 770 + 7 111 -7 777 8 1000 -8 7000 cn*bn + .. + c2*b2 + c1*b1 + c0*b0

9 Common Binary Procrustean representation Most are binary with a fixed number of (8, 16, 24, 32, 64). They are called procrustean, after the Greek legend of Procrustes, or PolyDemon, who had an iron bed, placed people on it, and if they were too tall he chopped them off to the fixed size; if they were too short he stretched them to this fixed size. registers, words, etc are also fixed size.

Signed Magnitude (s&m) A simple way of representing binary numbers which are positive or negative is to specify the sign as the first binary digit (or bit). A negative sign is 1; a positive sign is 0. For example, with 4 bits, there are 16 possible integers as shown. Notice however that there are two zeros, a positive and a negative one. Not good! Binary numbers (base 2) i s&m i s&m +/- c2 c1 c0 0 0000 -0 1000 2 1 0001 -1 1001 4 2 1 2 0010 -2 1010 Sign 3 0011 -3 1011 4 0100 -4 1100 0 is + * * * 1 is - 5 0101 -5 1101 6 0110 -6 1110 + 7 0111 -7 1111

10 Ones Complement Another way of representing negative numbers is to do a complement; to complement or “Not” each bit of the positive number to get the negative. For example, with 4 bits, the 16 possible integers are shown below. Notice again however that there are two zeros, a positive and a negative one. Not good.

The conversion of a number to its negative is shown in the data diagram below.

i 1comp i 1comp cn ... c2 c1 c0 0 0000 -0 1111 2 1 0001 -1 1110 2 0010 -2 1101 ! ! ! ! 3 0011 -3 1100 4 0100 -4 1011 5 0101 -5 1010 cn c2 c1 c0 6 0110 -6 1001 2 7 0111 -7 1000

11 Twos Complement Yet another way of representing negative numbers is to do another kind of complement; to view the negative numbers as a cyclic odometer as on a vehicle. A 4 bit system, goes forward, from 0000 to 1111 and then repeats starting with 0000. Going backwards from 0000, the next value (which is 1111) corresponds to -1. Similarly for -2, -3, etc to -8. There is only one value for zero, and the values range from -8 to +7. In general for n digits the values range from -2n to 2n - 1 Such a 2s complement is most commonly used in computers, with more than 4 bits.

The 2s complement negative numbers are just one more than the 2s complement, so to create the 2s complement, simply invert all the bits and add 1 to the result. i 2comp i 2comp +2 = 0010 0 0000 -1 1111 +2 = 0010 1 0001 -2 1110 +4 = 0100 2 0010 -3 1101 3 0011 -4 1100 -5 = 1011 4 0100 -5 1011 +2 = 0010 5 0101 -6 1010 -3 = 1101 6 0110 -7 1001 -5 = 1011 7 0111 -8 1000 -2 = 1110 -7 = 1001 The sum of two numbers in 2s complement is shown to the right, in three examples. Note the last example, adding bit by bit yields a final carry of 1, which is ignored. Recall that these complement systems are procrustean; they hold for a fixed size only. 12 Questions involving Number Representations.

1. Drill and Kill a. Represent the decimal number 49 in all the various bases 2, 3, 4, 5, 6, 7,8 9 , 10, 12,16, 20. b. What decimal number is represented by 1001001 in bases: 2, 3, 4, 5, 6, 7,8 9 , 10, 12,16, 20. c. Show the addition of 66 and 99 in 2s complement. d. Add the hex numbers ABC and DEF.

2. How many integers can you represent with your 10 fingers?

3. Octal tøfrom Binary Relate a number such as 49, in binary and octal; Show how to convert from one to the other very conveniently.

4. Create a 3-valued integer system with negative coefficients, and represent a dozen values in this system.

5. Create a tens-complement system.

6. Create a of positive integers.

7. Create your own number system; Can you use a base such as 1/2, 2/3, 0.7, or ?

13 More Questions involving Number Representations.

1. Base 13 Consider a base 13 system with coefficients ranging from 0 tdo 9 and including JS, K and L (for 10, 11, 12) respectively. Convert the following numbers into base 10 equivalent numbers a. K9 b. KKK

Convert the following decimal numbers into base 13 c. 49 d. 100

2. Pex: base 32 Consider a system with base 32, represented by 5 bit cominations With the 32 pex digits ranging from 0 dto 9 and then A, B, C .. W excluding the letter 0 which could be confused by the digot 0. Write the following binary in thiss pex notation, by bunches of 5 bits 1 11010 01001 Then convert this pex integer into a decimal integer. Check your answer in another way.

3. Radix Suppose that the coefficients of a radix system are -1, 0 and 1 And the base is also negative at -3. Show the 15 decimal digits (7 to -7) when converted to this system (I.e. count from 7 down to 0 and then continue to -7. 14 Even More Questions involving Number Representations.

1. Odd Radix If the coefficients of a radix system are the positive odd integers 1, 3, 5, 7, … represent the integers 0 to 16 by this system. Observe the squares 2, 4, 9, 16. What is the smallest set of digits needed to represent all positive integers?

2. Non 9 Decimal System An integer can be represented in a decimal system with the ten digits: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8 (but not 9).

Use this system to represent the 0, 19, and -9.

3. Many Complements Write the -7 in binary twos complement form For the following size of register: 4, 5, 7, 9.

15