Understanding Number Systems & Their Representation in Computers - Prof. David Evans, Study notes of Computer Science

Lecture notes on number systems, covering the concept of numbers versus numerals, positional number systems, conversion between different bases, and systems of special interest such as binary, octal, and hexadecimal. It also discusses integer representation in real computers, arithmetic on positional systems, and representation of other scalars like alphanumeric characters and real numbers.

Typology: Study notes

Pre 2010

Uploaded on 03/09/2009

koofers-user-t5y
koofers-user-t5y 🇺🇸

9 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS216 Lecture Notes on Number Systems (Last Edit: 4/6/00) 1
Lecture Notes on Number Systems
1. Question: Which is the bigger number?
5 3 2 (ans 5)
Alternative question: Which is “five”?
five V cinq 101 (ans none)
The point: These are all names of the abstract notion of ‘fiveness’. We can invent LOTS of
other systems to name numbers. NUMBER != NUMERAL
2. Positional (Polynomial) Number Systems
Example: decimal: 346 = 3*100 + 4*10 + 6*1
general: “radix R” or “base R”:
Integers
and
Reals
The “d’s” are generally 0, 1, ... R
Common notation: dddR
Do some examples: binary, ternary, octal,hexadecimal.
3. Conversion
Radix R - to - Decimal: Compute the expansion
dndn1 ...d0diRi
×
i0=
n
=
d
ndn1 ...d0d1 d2 ...dm
diRi
×
im=
n
=
Radix Point
nd
nRn... d0R0
++=
pf3
pf4
pf5

Partial preview of the text

Download Understanding Number Systems & Their Representation in Computers - Prof. David Evans and more Study notes Computer Science in PDF only on Docsity!

Lecture Notes on Number Systems

1. Question: Which is the bigger number?

5 3 2 (ans 5)

Alternative question: Which is “five”?

five V cinq 101 (ans none)

The point: These are all names of the abstract notion of ‘fiveness’. We can invent LOTS of other systems to name numbers. NUMBER != NUMERAL

2. Positional (Polynomial) Number Systems Example: decimal: 346 = 3100 + 410 + 6*

general: “ radix R” or “base R”:

Integers

and

Reals

  • The “d’s” are generally 0, 1, ... R

• Common notation: dddR

Do some examples: binary , ternary, octal , hexadecimal.

3. Conversion Radix R - to - Decimal: Compute the expansion

d (^) n d (^) n – 1 ... d 0 d (^) i × R i i = 0

n

dn d (^) n – 1 ... d 0 • d (^) – 1 d (^) – 2 ... d (^) – m d (^) i × R i i =– m

n

Radix Point

n d (^) n R n ... d 0 R 0 = + +

Decimal - to - Radix R

Algorithm:

  • Divide succesively by R.
  • Note remainder at each step. (order of digits is lsb to msb)

Radix R 1 to Radix R (^2)

R 1 to decimal to R (^2)

4. Systems of Special Interest Binary base 2 Easy for computers Octal base 8 Easier for people Hexadecimal base 16 Easier for people

Show conversion between all of these

Emphasize hex numbering 0 ... 9ABCDEF

5. Integer Representation in Real Computers Issues: Fixed Size, Negative Number Representation A. Fixed Size “The XXX is a 16-bit (vs 32-bit) computer ...” If “word” size is n bits

there are 2 n^ possible bit patterns so only 2n^ possible distinct numbers

Implications:

  • Cannot represent all possible numbers!!
  • Must use some of these bit patterns (half?) to represent negative numbers.

B. Negative Number Representation i. sign magnitude (the obvious one)

  • reserve one bit for the sign
  • rest of bits are interpreted directly as the number

n R

--- d (^) n R n – 1 ... d 1 R 0 = + + ,with remainder d 0

0 n-

Negation: Complement means flip the bit, so flip every bit and add one Example (R=2, n=8): 9510 0010111 flip 1101000 add 1 1101001 (-95) Note that “re-negating” gets us back to the original.

Notes:

  • One zero (this is good)
  • Arithmetic easy (we’ll see)

iii. excess B Represent k (whether + or -) as k + B

Note: allows asymetric range.

6. Arithmetic on Positional Systems A. General Arithmetic We all know how to do arithmetic in radix 10 using carries

Same in other radices, just use a different table. Example: Our hero, binary.

B. Sign magnitude

  • Add the operands, then check the signs and the magnitudes of the operands to deter- mine the sign of the result.
  • It’s a pain and expensive to do in hardware, lots of comparisons and control required.

0 B-1 B R^ n

-B -1^0 R n-B-

<sum,carry>

0,0 1,0 2, 1,0 2,0 3,0 0,

9,

1,0 0, 0,1 1,

0,0 1, 1,0 0,

Carry in 1

C. 2’s complement

  • Addition and subtraction are easy. Add the two numbers and throw away the carry.
  • Don’t need to worry about the signs of the operands.

Examples : Assume 4-bit computer, first bit is sign bit.

D. Overflow i. Demonstration

We call this OVERFLOW. The number “13” is not representable in a 4-bit, 2’s complement computer.

Question: Does the problem go away if we have more bits? Answer: Nope, not in general, though we could safely add 6+7 with more bits.

ii. Detection.

  • Examine the signs of the operands and the result.
  • If signs of operands are different, cannot have overflow.
  • If sign of operands are the same and the sign of the result is different, overflow!!
  • These checks are easy to do in hardware. 7. Representation of Other Scalars A. Alphanumeric characters 8-bit byte 7-bit ASCII code 1 ‘a’ = 61 16 ‘A’ = 41 16 ‘;’ = 3B ‘z’= 7A 16 ‘Z’ = 5A 16 ‘ ‘ = 2016 B. Real numbers i. Fixed Point
  • Given n bit number, radix point is “fixed” at some bit f
  • So f “integer” bits and n-f “fractional” bits
  1. ASCII -- American Standard Code for Information Interchange.

OY!! That’s Negative??!!

  • single representation of zero -- exponent and fraction are all 0

8. IMPORTANT!!

Question : What’s the value of “0110010110111001”? Answer: You CANNOT tell. There is no notion of TYPE at the bit level in computers. These notions are realized at higher levels.

Table 1: IEEE Floating Point Standard.

Single Double

Mantissa bits(incl hidden) 24 53

sign bits 1 1

exponent bits 8 11

Bias/Excess 127 1023

Max Exponent 127 1023

Min Exponent -126 -