course content

Course Content

Numeral Systems 101

Practice CipheringPractice Ciphering

So far so good 😉.

As you already know how to convert decimal numbers to binary, a useful step is to learn how to do the opposite action. As you get familiar with the previous steps this one is not going to be a challenge for you. 1 in binary code is still one, 0 is still zero, but here you have 8 numbers so 9 should be converted properly 0->0 1->1 2->2 3->3 4->4 5->5 6->6 7->7.In the example, we define 1234 as a decimal number.

  1. You need to divide the number by 8, and take down the remainder of the division.
  2. Then you should calculate the received number and implement the first step to it.
  3. You can stop if division results in 0.
  4. Rewrite remainders in the reversed order.
Binary numeral system

As mentioned, the more practice the better. Here you are going to make a complex task where you will work not only with a list of converted numbers but with string: it means that you should not only append remainders but convert it to strings firstly. Try to do the task to see beautiful representations in string.

Task

Write the code that will decode the number 3196 from the decimal numeral system to octal. Fill the gaps and follow the algorithm. If everything is correct you will receive another special number 🤯, the explanation is waiting for you at the end of the chapter.

  1. Define an empty list for storing the octal_number.
  2. Print the decimal_number variable.
  3. Check if the decimal_number variable is 0.
  4. Append 0 if decimal_number variable is 0.
  5. Define the loop which works while decimal number is not 0.
  6. Count the remainder of division decimal_number by 8.
  7. Append converted remainder to the list of octal numbers.
  8. Decrese decimal_number using integer division it by 8.
  9. Make the string of octal numbers reversed.

Note

I bet you've received 6174. This is a Kaprekar's and it is called after the mathematician D.R. Kaprekar.Try to do the simple calculation with a number that consists of at least two different digits: 5678 for instance. Firstly write this number in descending and ascending order and subtract it: 8765-5678 = 3087, then we will do the same, but with the number 3087 8730 - 0378 = 8352, the same here 8532 - 2358 = 6174 7641 - 1467 = 6774. You can apply the same algorithm to different numbers and you will receive 6174 every time.

Everything was clear?

Section 2. Chapter 2
toggle bottom row