CH 2 Binary Numbers 2015
CH 2 Binary Numbers 2015
Chapter 2
1
Logic:
A statement is either True or False
Often represented by a T or F.
Electrical Circuits:
A lamp will be On or Off
A circuit can have current flow or no flow (switch on or
off)
Polarity:
Positive or negative.
2
How many ones make up 642???
600 + 40 + 2 ?
i.e. 6 hundreds, 4 tens, and 2 ones
6x102 + 4x101 + 2x100
What would it mean if we counted in
eights?
6x82 + 4x81 + 2x80
Then it would mean 418 counting in tens.
3
642 in base 10 positional notation is:
5
R is the base
of the number
As a formula:
642 is 63 * 102 + 42 * 10 + 21
7
6
Can you show that this representation must
always be unique?
7
Binary numbers are numbers where
the BASE IS 2
This means there can only be two digits 0 and
1 (Why?)
Counting in Binary:
0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001
and so on...
Why does Base 2 interest us so much?
8
Octal is where we use BASE 8
The digits are then 0, 1, 2, 3, 4, 5, 6, 7
9
10
What is 1010 (as a base 10 number) if the
base is 2, 8, 10 and 16?
10
520
1010
4112
11
1. Computers represent data in binary code:
off/on, false/true, 0/1;
2. Thus we would like to represent numbers in
such a format;
3. We can represent numbers in any base. We
are used to base 10 but this is habit; it is not
driven by mathematics;
E.g. 642 is 63 * 102 + 42 * 10 + 21
4. In base R the number dn dn-1 … d2 d1 means:
dn * Rn-1 + dn-1 * Rn-2 + ... + d2 * R + d1
5. Arithmetic works in any base exactly as in base 10.
12
R is the base
of the number
As a formula:
1202
642 = 164*8*3 10
+ 22 +*842 +*010 1 1+ +22
*8
3 3 2 2 11
110091807060504031201 7
13
Addition in Base 2:
We want to add the two numbers
1010111 and
1001011
14
Remember that there are only 2 digits in binary,
0 and 1
1 + 1 is 0 with a carry
Carry Values
1011111
1010111
+1 0 0 1 0 1 1
10100010
15 14
Let’s take 111011 away from 1010111.
16
Remember borrowing? Apply that concept
here:
12
202
1010111
- 111011
0011100
17
Mark groups of three (from right)
This is because three binary digits exactly
represent the octal digits 0, 1, 2, 3, 4, 5, 6, 7
i.e. 000, 001, 010, 011, 100, 101, 110, 111
Example: Convert 10101011 to octal
18
Mark groups of four (from right)
This is because each group of four binary
digits represents one hexadecimal digit
19
Algorithm for converting number in base 10
to other bases:
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
20
We write out the number in decimal, but
expand it in terms of the new base R:
N = dn * Rn-1 + dn-1 * Rn-2 + ... + d2 * R + d1
Divide by the base and take the remainder:
N/R = dn * Rn-2 + dn-1 * Rn-3 + ... +d3R+ d2
Remainder is d1.
Repeating:
N/R2 = dn * Rn-3 + dn-1 * Rn-4 + ... +d4R+ d3
Remainder is d2.
AND SO ON…
21
What is 1988 (base 10) in base 8?
22
248 31 3 0
8 1988 8 248 8 31 8 3
16 24 24 0
38 08 7 3
32 8
68 0
64
4
Answer is : 3 7 0 4
23
What is 3567 (base 10) in base 16?
24
222 13 0
16 3567 16 222 16 13
32 16 0
36 62 13
32 48
47 14
32
15
So result is DEF
25
We can extend the idea of working to
different bases to the fractional part of a
number.
26
dn * 2n-1 + dn-1 * 2n-2 + ... + d2 * 21 + d1 * 20
(radix point) + d-1 * 2-1 + d-2 * 2-2 + d-3 * 2-3
+…
Thus (binary) 101.011means:
22 + 20 + 1/22 + 1/23
= 5 3 /8
What would hexadecimal A5.FF be in decimal?
165 255/
256
27
Suppose the fraction is in Base 10 and we
want to convert to another base.
28
dn * 2n-1 + dn-1 * 2n-2 + ... + d2 * 21 + d1 * 20
(radix point) + d-1 * 2-1 + d-2 * 2-2 + d-3 * 2-3
+…
Keep only the radix part:
(radix point) + d-1 * 2-1 + d-2 * 2-2 + d-3 * 2-3 + …
Multiply by 2:
d-1 (radix point) + d-2 * 2-1 + d-3 * 2-2 + …
29
Convert 0.1to binary, hexadecimal, and octal
.00011,
.19
.06314
30
Subtraction of Binary fractions
10110.000
- 1010.011
ANS 1011.101
31
Bit (Binary digit)
Byte 8 bits
32-bit machines
64-bit machines
32
Understand the importance of Binary digits
to data representation in computers;
Understand the positional representation of
numbers in different bases;
Understand the relationship between base 2,
and base 8 and base 16 numbers;
Convert from base R to base 10;
Convert from base 10 to base R;
Do arithmetic in different bases.
33