Positional notation of unsigned integers The base - b positional - - PDF document

positional notation of unsigned integers
SMART_READER_LITE
LIVE PREVIEW

Positional notation of unsigned integers The base - b positional - - PDF document


slide-1
SLIDE 1

1

  • 02 Information theory

02.02 Binary arithmetic

  • Positional notation
  • Unsigned integers
  • Unsigned fixed-point
  • Signed numbers
  • Floating point numbers
  • Base conversions
  • Binary arithmetic
  • Positional notation
  • f unsigned integers

1 1 2 2 1 1

... b c b c b c b c

n n n n

+ + + +

− − − −

1 2 1

... c c c c

n n − −

  • The base-b positional representation of an

integer number of n digits has the form

  • The value of the number is
  • n digits encode all integer numbers from 0 to

bn-1

Example: b=2, n=5 10011=1*16+1*2+1*1=19 11111=31=25-1

(1) (2)

slide-2
SLIDE 2

2

  • Base conversion

1 1 2 2 1 1

... b c b c b c b c

n n n n

+ + + +

− − − −

  • From base b to decimal:
  • From decimal to base b:

digits from c0 to cn-1 are obtained as remainders of subsequent divisions by b of the digital number

1 3 2 2 1 1 1 2 2 1 1

c b ) b c ... b c b c ( b c b c ... b c b c

n n n n n n n n

+ + + + = = + + + +

− − − − − − − −

(2) (3)

  • Base conversion

example

(29)(10)=(11101)(2) (11001)(2)=(25)(10)

29 29 14 1 29=14*2+1 14 7 14=7*2+0 7 3 1 7=3*2+1 3 1 1 3=1*2+1 1 1 1=0*2+1

position digit weight 1 1 1 + 1 2 0 + 2 4 0 + 3 1 8 8 + 4 1 16 16 25

slide-3
SLIDE 3

3

  • Fixed-point notation of

unsigned rational numbers

m m n n n n

b c ... b c b c b c ... b c b c

− − − − − − − −

+ + + + + + +

1 1 1 1 2 2 1 1

m n n

c ... c . c c ... c c

− − − − 1 1 2 1

  • The base-b positional representation of a

rational number of n+m digits has the form

  • The value of the number is
  • n+m digits encode all rational numbers of the

form

m

Num 2

with

1 2 − ≤ ≤

+m n

Num

(4) (5) (6)

  • Base conversion
  • From base b to decimal:
  • From decimal to base b:

– Solution 1: Given a digital number X=Num/2m, convert Num and shift the decimal point m positions left – Solution 2: Given a digital number X=Xint.Xfrac, convert the integer part Xint as outlined before, then convert the fractional part Xfrac obtaining each digit as the integer part of the result of subsequent multiplications by b:

m m n n n n

b c ... b c b c b c ... b c b c

− − − − − − − −

+ + + + + + +

1 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 − − − − − − − − − − − −

+ + = + +

m m m m

b c ... b c c b ) b c ... b c b c (

(7) (5)

slide-4
SLIDE 4

4

  • Base conversion

example

(29.375)(10)=(11101.011)(2)

29 29 14 1 29=14*2+1 14 7 14=7*2+0 7 3 1 7=3*2+1 3 1 1 3=1*2+1 1 1 1=0*2+1 0.375 *2 = 0.75 = 0 + 0.75 0.75 *2 = 1.5 = 1 + 0.5 0.5 *2 = 1 = 1 +

  • Binary arithmetics
  • Binary addition:
  • Binary multiplication:

1 1 1 1 10

1 1 1 1 1 5 1 1 1 1 6 1 1 2 1 1 1 1

1 1 1

1 2 1 3 3 6

1

2

  • 1

5 6 1 1 1 1 1 1 1 1

  • 1

1

  • 1

1

  • 1

1 1 1

slide-5
SLIDE 5

5

  • Signed numbers
  • Sign bit: 0=positive, 1=negative

(3)(10) = 0 0011; (-3)(10) = 1 0011

  • 1’s complement

(3)(10) = 0 0011; (-3)(10) = 1 1100 = (0 0011)’

  • 2’s complement

(3)(10) = 0 0011; (-3)(10) = 1 1101 = (0 0011)’+1

  • 2’s complement numbers
  • The 2’s complement representation of a negative

number (say, -v) is obtained from the representation of v, by complementing each bit (including the sign bit) and adding 1

  • vv’+1
  • The resulting binary configuration corresponds to the

unsigned number 2n-v (i.e., the complement of v to 2n), where n is the total number of digits, including the sign bit.

2n v

  • v

2n-v positive negative

slide-6
SLIDE 6

6

  • 2’s complement arithmetic
  • 2’s complement numbers can be added by using the

conventional rules of binary addition a+(-b) a+(2n-b)=2n-(b-a)-(b-a)=a-b

  • Example:

(3)(10)-(5)(10) (00011)(2)-(00101)(2) = (00011)(2)+(-00101)(2) (00011)(2c)+(11011)(2c) = (11110)(2c) (-00010)(2) (-2)(10)

  • Floating point numbers
  • s = sign (1 bit)
  • M = Mantissa (m bits)
  • b = base (0 bits)
  • se = exponent sign (1 bit)
  • E = exponent (e bits)

Encoding floating point numbers requires words of n digits, with n=1+m+1+e

s•0.M•bse•E

slide-7
SLIDE 7

7

  • Floating point encoding

1. Start from a fixed-point binary encoding using a sufficient number of bits 2. Evaluate the number of shifts required to bring the most significant 1 in position –1 3. Take as mantissa (M) the most significant m bits (starting from the first 1) of the fixed-point encoding 4. Set se=1 if the number is lower than 0.5, se=0

  • therwise

5. Assign the exponent E with the binary representation of the number of shifts computed at step 2 6. Set the sign bit s as usual s•0.M•bse•E

  • Floating point encoding

s•0.M•bse•E

(40)(10)

5 4 3 2 1

  • 1

1 0 1 0 0 0 .

6 positions

1 0 1 0 1 1 0

Example: m=4, e=3

s M se E (-19)(10)

5 4 3 2 1

  • 1

0 1 0 0 1 1 .

5 positions

1 0 0 1 1 0 1 1

s M se E (0.1)(10) 3 positions

1 1 0 0 0 1 1 1

s M se E

  • 1 -2 -3 -4 -5 -6 -7 -8

. 0 0 0 1 1 0 0 1 ...

40

  • 18

0.09375

slide-8
SLIDE 8

8

  • Floating point arithmetic

A AE

se A A

M . s A 2 =

B BE

se B B

M . s B 2 =

B B A A

E se B B E se A A

M . s M . s B A C 2 2 + = + =

A A A A B B

E se E se E se B B A A

M . s M . s 2 2 2

  • +

=

( )

A A B B A A

E se ) E se E se ( B B A A

M . s M . s 2 2

− −

+ =

B B A A

E se B B E se A A

M . s M . s B A C 2 2 ∗ = ∗ =

( )

B B A A

E se E se B B A A

M . s M . s 2 2 ∗ ∗ =

( ) (

)

B B A A

E se E se B B A A

M . s M . s

+

∗ = 2

  • Floating point arithmetic

s•0.M•bse•E

A = 3.5 = +0.111*2+2 B = 1.5 = +0.110*2+1

E A . 1 1 1 2 B . 1 1 0 1 A . 1 1 1 2 B . 0 1 1 2 C 1 . 0 1 0 2 C . 1 0 1 3 M

C = A+B = 5 = +0.101*2+3 A = 3.5 = +0.111*2+2 B = 1.5 = +0.110*2+1 C = A*B = 5.25 = +0.10101*2+3

E A . 1 1 1 2 B . 1 1 0 1 C . 1 0 1 0 1 3 C . 1 0 1 3 M

5