|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bitstrings |
|
|
|
|
N-bit number: |
|
|
|
|
bN-1 bN-2...b1b0 |
|
|
|
Can also think of this as
a string of digits 0 and 1. |
|
|
How many possible
patterns for N-bit string? |
|
|
|
Each bit bi can have 2 possible values |
|
|
|
There are N such bits |
|
|
|
|
Therefore, total number
of patterns is |
|
|
|
2 * 2 * . . . * 2 = 2N |
|
(Important
Binary Number Fact #1) |
|
|
How many different
VALUES? (trick question) |
|
|
|
It depends on the representation being used. (We will look at several.) |
|
How many bits does it
take to represent a given number N? |
|
|
|
With K bits we can
represent numbers up to 2K |
|
|
|
So, we want to find K
such that |
|
|
|
|
2K >= N |
|
|
|
|
|
Expressing this in terms
of logarithm base 2, |
|
|
|
lg (2K) >= lg N |
|
|
|
|
|
K lg 2 >= lg N |
|
|
|
|
|
K >= lg N |
|
|
|
|
|
K = ceil (lg N) |
|
|
(Important
Binary Number Fact #2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|