course content

Course Content

Numeral Systems 101

Get Acquainted with Binary CodeGet Acquainted with Binary Code

I guess you got wind of the fact that computers see your code differently than you: this bright machine can read binary code, which consists of 0 and 1. The binary code looks like this 00011100, but zeros in forwarding positions are optional, so you can remove it and write the code like 11100. It is easy for a computer, but a challenge for humans; therefore, you are going to get familiar with deciphering it:

Rule

Here you should do the same operations as in the previous chapter. Find the index of a number(it still begins from the right ) and then multiply the current number by 2 raised to the power of the index. For instance 101->1x2^2 + 0x2^1 + 1x2^0 = 4 + 0 + 1 = 5.

Usage of binary system

The main point of using binary code is that a computer consists of billion transistors that respond to binary signals 0 or 1; hence, "computer words" that include only 0 and 1 send signals to transistors, 1 means on, and 0 means off.

Task

It's time to hone in on your skills! Convert a number from binary numeral system to decimal one and print the result. You should follow the algorithm on the right and fill the gaps. As the result, you will receive one of the magic numbers. But the explanation is waiting for you at the end of the chapter.

  1. Define the variable power and assign 0 to it.
  2. Count the remainder of division binary_number by 10.
  3. Multiply last_digit by the 2 raised to the relevant power.
  4. Add the result to a decimal number.
  5. Increase power by 1.
  6. Print the decimal_number.

Note

I guess that you received 1729 and want to know why I claimed that this number is magic? Everything is completely clear: It is called Hardy-Ramanujan number after an anecdote about one of British mathematician G.H Hardly. If you find this information gripping you can read about the anecdote in 'The Man Who Knew Infinity by Robert Knaigel. It is the smallest number that you can express like the sum of two different cubes in two different ways. 1729 can be calculated as the sum of the cubes of 10 and 9, a cube of 10 is 1000 also the cube of 9 is 729, and the sum of the cubes of 12 and 1.

Everything was clear?

Section 1. Chapter 2
toggle bottom row