Skip to content

Commit

Permalink
Added all exercises files to the repository.
Browse files Browse the repository at this point in the history
  • Loading branch information
xorpd committed Jun 20, 2014
1 parent c26fec2 commit 77b193e
Show file tree
Hide file tree
Showing 121 changed files with 9,524 additions and 0 deletions.
49 changes: 49 additions & 0 deletions 1_binary/0_add_sub/ex/ex_add_sub.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Base 2
======

Binary addition and subtraction exercises
-----------------------------------------

If you have no previous experience in the binary base, it is crucial that you
solve all the exercises here. Make sure to solve everything before you move on
with the course.

Anything marked with *Bonus* is not required for you to understand the following
material, however It will probably make you smarter.


0. Addition. Solve the following. Write the solutions in base 2.
Use a pen and a paper.
Note: {100}_2 means 100 in base 2.

0.0 {100}_2 + {1}_2 = ?

0.1 {1111}_2 + {1}_2 = ?

0.2 {1001110}_2 + {111011}_2 = ?

0.3 {1101}_2 + {1101}_2 = ?

0.4 {1101}_2 + {1101}_2 + {1101}_2 + {1101}_2 = ?

0.5 Bonus: How much is {8}_10 * {1101}_2 ? (in base 2)
Note: * means multiplication.

1. Subtraction. Solve the following. Use a pen and a paper:

1.0 {100}_2 - {1}_2 = ?

1.1 {11000}_2 - {11}_2 = ?

1.2 {11001101}_2 - {1011}_2 = ?

1.3 {1000000}_2 - {111011}_2 = ?

1.4 {10101}_2 - {1010}_2 = ?

1.5 {1000}_2 - {100}_2 = ?

1.6 {1100}_2 - {110}_2 = ? (Bonus: Could you guess it?)


Happy thinking :)
177 changes: 177 additions & 0 deletions 1_binary/1_base_conversion/ex/ex_base_conversion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
Base 2
======

Base conversion exercises
--------------------------

Hey, some Base conversion exercises are included here. The first ones are pretty
usual, and could be dull at times, but please do them if this is your first time
with base 2. Also, make sure that you do them with a pen and a piece of paper. I
can't emphasize it more, you got to get the feeling through the hands, at least
on the first time.

As you move on with the exercises there are some that require more thinking.
As usual, anything marked with *Bonus* is not required for you to understand the
following material, however it will probably make you smarter.


0. Binary to Decimal conversion. Convert the following numbers to base 10:

You may use a calculator if you feel like it, however please don't use the
built in conversion function.

It is important that you do this yourself, to make sure that you get the
feeling of it. Some things could only be learned through the hands.


0.0 {10}_2 = ?

0.1 {100}_2 = ?

0.2 {101}_2 = ?

0.3 {1001110}_2 = ?

0.4 {100110011}_2 = ?

0.5 {111111}_2 = ?

0.6 {1000}_2 = ?

0.7 {10000}_2 = ? (Bonus: Could you guess this one? How?)


1. Decimal to Binary conversion. Convert the following numbers to base 2:

1.0 {2}_10 = ?

1.1 {5}_10 = ?

1.2 {83}_10 = ?

1.3 {134}_10 = ?

1.4 {128}_10 = ?

1.5 {63}_10 = ?

1.6 {256}_10 = ? (Bonus: Could you guess this one? How?)


2. Conversion between various bases and 10:

Make sure that you pick a smart method to do the conversion in the following
exercises :)

2.0 {2312}_5 = {?}_10 ?

2.1 {10120}_3 = {?}_10 ?

2.2 {121}_10 = {?}_3 ?

2.3 {121}_10 = {?}_6 ?


3. Conversion between two arbitrary bases.

Convert the following numbers' representations.

Hint: Given that you know how to convert to base 10 and from base 10 easily,
you could just use base 10 as a mediator base.

Example: {102}_3 = {?}_5 ?

Solution:
First we convert from base 3 to base 10.
We use Direct Evaluation method:

{102}_3 = 2*3^0 + 0*3^1 + 1*3^2 = 2 + 0 + 9 = {11}_10

Now we want to convert the result from base 10 to base 5. We use the
Remainder Evaluation method:

11 | 1 11 % 5 = 1
2 | 2 2 % 5 = 2

We obtain the number {21}_5. Hence {102}_3 = {21}_5

3.0 {10010}_2 = {?}_5 ?

3.1 {102}_3 = {?}_2 ?

3.2 {11011}_2 = {?}_3 ?

3.3 {1402}_5 = {?}_2 ?


4. Bonus: For the mathematically inclined:
(I still recommend you to at least read this. You might find it
interesting.)

4.0 Existence of representation:

During the presentation we implicitly assumed that there is a
representation in base 2 for every number that could be represented in
base 10. How could you prove it?

Generally, how could you prove that using base b for some b > 1, every
integral quantity could be represented in base b?

4.1 Uniqueness of representation:

During the representation we mentioned that every quantity could be
represented in a unique way in base 2. That means: Every quantity could be
represented as a sum of distinct powers of 2 in a unique way. prove it.

Generally: Let b be some base for b > 1. Show that for any quantity
q, there is only one way to represent q in base b.

Hint for b=2:
Assume that there are two different representations as sums of distinct
powers of 2 for the same quantity q. Then we get:
2^(a_0) + 2^(a_1) + ... = q = 2^(b_0) + 2^(b_1) + ...
Cancel the similar terms from the two sides of the equation, and try to
understand if equality is possible.


5. Bonus: Symmetry of bases:

5.0 We now know that there is nothing special about base 10. Why then do we
use it as a mediator in Question 3, instead of converting directly between
two arbitrary bases?

5.1 Once in a lifetime experience: Try to convert the number
{1241}_5 into base 3 directly, without using base 10 as a mediator. (Use
your mind, a pen and a paper).


6. Bonus: Divisibility by interesting numbers.

6.0 How could you check if a binary represented number is divisible by 2?
And By 4? Could you generalize it?

*6.1* How could you check if a binary represented number is divisible by 3?


7. Bonus: Complexity of conversion algorithms.
Required: Basic understanding of what is complexity.

It might be interesting to find out how fast do the base conversion
algorithms work.

For example: looking at the execution of the Direct Evaluation method while
converting a number n from base b to base c: The algorithm iterates over all
the digits of the number n, and invokes one addition operation and one
exponentiation for every digit. A total of about O(log{b}(n)) operations.

In this context we choose basic operations to be addition, subtraction,
division and exponentiation.

7.0 What is the amount of basic operations it takes to run the "Finding
largest power" method?

7.1 What is the amount of basic operations it takes to run the "Remainder
evaluation" method?


Happy thinking :)
93 changes: 93 additions & 0 deletions 1_binary/2_hexadecimal/ex/ex_hexadecimal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Base 2
======

Base 16 exercises
------------------

Hello! Some Base 16 related exercises are included here. As usual, the first
exercises are a bit easy (And might be boring), however it is very important
that you do those if you want to do the next ones, and especially if you want to
understand the rest of the course. We are going to use base 16 everywhere in
this course.

To make sure that you understand things right, Use a calculator from time to
time to check your answers. The Windows calculator (When in Programmer mode) has
the feature of changing the base of the current number. It has the built in
options of Hex, Dec, Oct(Octal - base 8) and Bin. Use those to check your
answers.

Although you could use a calculator or a computer to solve the simpler
exercises, make sure that you do them with a pen and a paper.


0. Convert the following numbers to binary:

0.0 0xD = {?}_2

0.1 0xF = {?}_2

0.2 0x3A = {?}_2

0.3 0x4532 = {?}_2

0.4 0x9A9B = {?}_?


1. Convert the following binary numbers to base 16:

1.0 {10}_2 = {?}_16

1.1 {110}_2 = {?}_16

1.2 {1011}_2 = {?}_16

1.3 {11110101}_2 = {?}_16

1.4 {1111100}_2 = {?}_16

1.5 {1010101111001101}_2 = {?}_16


2. Convert the following numbers (Pay attention to the wanted result base):

2.0 {10110}_2 = {?}_8

2.1 {1100111}_2 = {?}_8

2.2 {101001}_2 = {?}_4

2.3 {3725}_8 = {?}_2

2.4 {57137}_8 = {?}_4 (Hint: Try to use base 2 as a mediator.)


3. Think of an easy way to convert numbers from base 16 to base 4, and vice
versa.


4. Basic divisibility rules:

4.0 How could you check if a number represented in base 16 is divisible by
2?

4.1 Bonus: How could you check if a number represented in base 16 is
divisible by 4? By 8?


*5*.Bonus: How could you check if a number represented in base 16 is divisible
by 3? And by 15? Could you think of another interesting divisibility rule?


6. Bonus: It is known that a number x has n digits when it is represented in
base 4. How many digits will x have when it is represented in base 8?


7. Bonus:
Required: Basic familiarity with the notion of complexity.

What is the computational complexity of the new hex to binary
conversion algorithm we learned about in this lesson? Is it faster than
using the Remainder Evaluation method?


Happy thinking :)
Loading

0 comments on commit 77b193e

Please sign in to comment.