You are on page 1of 38

Lecture 2

Number System

A numbering system assigns meaning to the


position of the numeric symbols.
Base

The base of a number determines the number of


digits (e.g. symbols) and the value of digit
positions.
Positional Notation: Decimal Number
Positional Notation: Decimal Number
Binary Number System

Digital computers are made up of electronic


circuits, which have exactly 2 states: on and
off.
Computers use a numbering system which has
exactly 2 symbols, representing on and off.
Binary Number System

Decimal is base 10 and has 10 digits:


0,1,2,3,4,5,6,7,8,9
Binary is base 2 and has 2, so we use only 2
symbols: 0,1
Binary Number System

Binary numbers are built by concatenating a


string of bits together.
Example: 10101010
Bit

It is a unit of information to communicate with


only two states.
Positional Notation: Binary Number
Converting Decimal to Binary
Converting Decimal to Binary

While (the quotient is not zero)


● Divide the decimal number by the new base*
● Make the remainder the next digit to the left in the
answer
● Replace the original decimal number with the
quotient
Converting Decimal to Binary

What is the binary equivalent of the decimal


number 201?
Converting Decimal to Binary
Converting Binary to Decimal
Converting Binary to Decimal

What is the decimal equivalent of the binary


number 10101011?
Converting Binary to Decimal
Converting Binary to Decimal: fractional numbers
Byte

1 byte = 8 bits

With 1 byte we can represent value of 0 - 255

For binary with 64 bits, we get 0 to (2^64)-1 or 0 to


18446744073709551615
Addition
There are 3 basic rules for adding binary
numbers:
1. 0 + 0 = 0
2. 0 + 1 = 1
3. 1 + 1 = 10. If the sum of 2 bits is greater
than 1, we need to shift a column on the left.
Solve

1011
+ 1101
Subtraction
Before trying subtraction, we need to
understand how negative numbers are
represented in binary. Signed number must all
have same number of bits. 0s are used to fill up
empty bits.
Subtraction

There are 3 basic standards for notating


negative numbers.
● Signed Magnitude
● 1's Complement
● 2's Complement
Signed Magnitude
In this notation, an extra bit is added to the left
of the number to notate its sign. 0 indicates +ve
and 1 indicates -ve.
Using 8 bits, +13 is 00001101 and +11 is
00001011. -13 is 10001101 and -11 is
10001011.
1's Complement

In this notation positive numbers are


represented exactly as regular binary numbers.
So 13 will be 00001101 and 11 will be
00001011.
1's Complement
Negative numbers are represented simply by
flipping the bit, i.e. 0's become 1 and 1's
become 0.
So -13 will be 11110010 and -11 will be
11110100.
Subtraction Using 1's Complement
In this method the number being subtracted has
to be negated using 1's complement and then
added (not subtracted) to the other number.
Since signed number must all have the same
number of bit, any ‘overflow’ bit has to be
added back to the rest of result.
Subtraction Using 1's Complement
If we want to do 13–11, we will do 13 + (-11) or
00001101 + 11110100. Adding these will result
100000001.
Notice it is 9 bits, so we keep the right most 8 bits
00000001 and add the ‘carry over’ 9th bit (1 in this
case) to it which gives us 00000010 = 2 = 13–11.
Subtraction Using 1's Complement
Now for 11–13 or 11 + (-13) = 00001011 +
11110010 = 11111101.
It has a 1 at the left indicating it as negative. Using
1's complement we can figure out the absolute
(positive) number which is 00000010 or 2.
So the result is -2.
Multiplication

The 3 basic binary multiplication rules are also


similar to decimal.
1. 1 * 1 = 1
2. 1 * 0 = 0 * 1 = 0
3. 0 * 0 = 0
Solve

1011
X 1101
Solution
1. 1011 * 1 (multiplier 1's col) = 1011
2. 1011 * 0 (multiplier 2's col) = 00000
3. 1011 * 1 (multiplier 4's col) = 101100
4. 1011 * 1 (multiplier 8's col) = 1011000
5. Sum up. 1011 + 00000 + 101100 + 1011000 = ((1011
+ 00000) + 101100) + 1011000 = (01011 + 101100) +
1011000 = 110111 + 1011000 = 10001111
Division
Binary division is similar to decimal division.
The only difference is that in decimal system,
since we are dividing traditional numbers, the
dividend (or portion of it) can be 0, 1 or more
than 1 times of the divisor. However in binary,
it can only be 0 or 1.
Division
Following decimal division convention
1. We check for a portion of dividend from its left that
is >= the divisor.
2. Then we subtract the multiple of the divisor that is
<= the portion of the dividend. The multiplier (1)
gets appended to the quotient and result of the
subtraction is the remainder.
Division

3. We bring down 1 bit at the time (going left to


right) for the remaining portion of the dividend
and check if the expression (remainder +
brought down bit) is >= the divisor. If not, we
append 0 to the quotient, or else we follow step
2 again.
Division

To divide 6 by 3 or 110 / 11
1. Is 1 (left most bit of 110) >= 11. No (we don’t need
to add 0 to quotient here since 0s on the left are
insignificant).
Division

2. Is 11 (left 2 most bits of 110) >= 11.


We add 1 (multiplier) to the quotient, and subtract 11
from 11. That gives us a remainder of 0.
Here, we are subtracting “one-one from one-one NOT
eleven from eleven”.
Division

3. Now we bring down the remaining bit (0) from


110. Is 0 >= 11. No. So we append 0 to the
quotient.
Since we have no more bits remaining in the
dividend, we stop here and check. Our remainder is
0 and quotient is 10 (binary) = 2.

You might also like