course content

Course Content

Numeral Systems 101

Get Acquainted with the Octal Numeral SystemGet Acquainted with the Octal Numeral System

There is another numeral system called octal. In comparison to binary or decimal, it consists of 8 digits, starting with zero: 0,1,2,3,4,5,6,7.

If you wonder why it was implemented, I want to clarify something.

Usage

As you remember the number in binary representation consists of several digits, one bite for each of them; but in an octal numeral system, three binary digits represent one octal. Therefore, you can represent one word for the computer using fewer symbols. Enormous strings of binary code can be represented in a more beautiful way for the computer; hence, less memory is filled. The principle of converting a number to the decimal system from octal one is the same as with binary:As you remember the number in binary representation consists of several digits, one bite for each of them; but in an octal numeral system, three binary digits represent one octal. Therefore, you can represent one word for the computer using fewer symbols. Enormous strings of binary code can be represented in a more beautiful way for the computer; hence, less memory is filled. The principle of converting a number to the decimal system from octal one is the same as with binary:

Rule

Algorithms of converting to decimal numeral system overlap for different numeral systems. Here is the same for octal number 221: the index of the left number 2 is 2, the index of the middle number 2 is 1 and the index of the number 1 is zero; but here we should multiply the numbers by 8 raised to the power of index. Hence, 221-> 2*8^2+2*8^1+2*8^0=128+16+2=146.

Task

Doing as many tasks as possible is a recipe for success! Write the code that will decode the number 117 from the octal numeral system to decimal. Fill the gaps and follow the algorithm. If everything is correct you will receive one special number 🧐 But the explanation is waiting for you at the end of this chapter.

  1. Print the octal_number.
  2. Define the loop which goes through the octal_number variable till it is zero.
  3. Assign the remainder of division octal_number by 10 to the variable last_digit.
  4. Multiply the received last_digit by the 8 raised to the relevant power.
  5. Decrease the octal_number using integer division by 10.
  6. Increase the power by 1.
  7. Print the decimal_number.

Note

I think you received 142857 which is called a cyclic number. Let me explain why:142857 x 1 = 142857 142857 x 2 = 285714 142857 x 3 = 428571 142857 x 4 = 571428 142857 x 5 = 714285 142857 x 6 = 857142. As you can recognize such multiplication results in a new number that is the same, but digits located in a different order; it creates a cycle. Another interesting fact for you🙄.

Everything was clear?

Section 2. Chapter 1
toggle bottom row