Course Content
Numeral Systems 101
2. Octal Numeral system
3. Hexadecimal Numeral system
Numeral Systems 101
Practice 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.
- You need to divide the number by 8, and take down the remainder of the division.
- Then you should calculate the received number and implement the first step to it.
- You can stop if division results in 0.
- Rewrite remainders in the reversed order.
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.
- Define an empty list for storing the
octal_number
. - Print the
decimal_number
variable. - Check if the
decimal_number
variable is0
. - Append
0
ifdecimal_number
variable is0
. - Define the loop which works while
decimal number
is not0
. - Count the remainder of division
decimal_number
by8
. - Append converted
remainder
to the list ofoctal numbers
. - Decrese
decimal_number
using integer division it by8
. - 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 number3087
8730 - 0378 = 8352
, the same here8532 - 2358 = 6174
7641 - 1467 = 6774
. You can apply the same algorithm to different numbers and you will receive 6174 every time.
Everything was clear?
Course Content
Numeral Systems 101
2. Octal Numeral system
3. Hexadecimal Numeral system
Numeral Systems 101
Practice 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.
- You need to divide the number by 8, and take down the remainder of the division.
- Then you should calculate the received number and implement the first step to it.
- You can stop if division results in 0.
- Rewrite remainders in the reversed order.
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.
- Define an empty list for storing the
octal_number
. - Print the
decimal_number
variable. - Check if the
decimal_number
variable is0
. - Append
0
ifdecimal_number
variable is0
. - Define the loop which works while
decimal number
is not0
. - Count the remainder of division
decimal_number
by8
. - Append converted
remainder
to the list ofoctal numbers
. - Decrese
decimal_number
using integer division it by8
. - 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 number3087
8730 - 0378 = 8352
, the same here8532 - 2358 = 6174
7641 - 1467 = 6774
. You can apply the same algorithm to different numbers and you will receive 6174 every time.
Everything was clear?