Зміст курсу
Numeral Systems 101
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.
# Defininig the decimal number decimal_number = 4321 # Creating a list for storing the converted binary number octal_number = [ ] # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Check if the decimal number is zero: further we will convert it till the number is zero if decimal_number == 0: # 0 in the octal numeral system is the representation of 0 in decimal one, so we append 0 to the list of the octal numbers octal_number.append(str(0)) #otherwise else: # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of dividing by eight remainder = decimal_number % 8 # Appending the converted remainder for creating an octal representation octal_number.append(str(remainder)) # This operation allows to decrease number eight times and work with the integer part of new one decimal_number = decimal_number//8 # Reversing the string octal_number = octal_number[::-1] # Joining all items of the string to make it more readable octal_number = " ".join(octal_number) # Printing the result print("The number in octal numeral system is:", octal_number)
Завдання
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.
Дякуємо за ваш відгук!
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.
# Defininig the decimal number decimal_number = 4321 # Creating a list for storing the converted binary number octal_number = [ ] # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Check if the decimal number is zero: further we will convert it till the number is zero if decimal_number == 0: # 0 in the octal numeral system is the representation of 0 in decimal one, so we append 0 to the list of the octal numbers octal_number.append(str(0)) #otherwise else: # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of dividing by eight remainder = decimal_number % 8 # Appending the converted remainder for creating an octal representation octal_number.append(str(remainder)) # This operation allows to decrease number eight times and work with the integer part of new one decimal_number = decimal_number//8 # Reversing the string octal_number = octal_number[::-1] # Joining all items of the string to make it more readable octal_number = " ".join(octal_number) # Printing the result print("The number in octal numeral system is:", octal_number)
Завдання
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.
Дякуємо за ваш відгук!
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.
# Defininig the decimal number decimal_number = 4321 # Creating a list for storing the converted binary number octal_number = [ ] # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Check if the decimal number is zero: further we will convert it till the number is zero if decimal_number == 0: # 0 in the octal numeral system is the representation of 0 in decimal one, so we append 0 to the list of the octal numbers octal_number.append(str(0)) #otherwise else: # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of dividing by eight remainder = decimal_number % 8 # Appending the converted remainder for creating an octal representation octal_number.append(str(remainder)) # This operation allows to decrease number eight times and work with the integer part of new one decimal_number = decimal_number//8 # Reversing the string octal_number = octal_number[::-1] # Joining all items of the string to make it more readable octal_number = " ".join(octal_number) # Printing the result print("The number in octal numeral system is:", octal_number)
Завдання
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.
Дякуємо за ваш відгук!
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.
# Defininig the decimal number decimal_number = 4321 # Creating a list for storing the converted binary number octal_number = [ ] # The text should be realised here due to the reason that further the decimal number will be changed print("The number in decimal numeral system is:", decimal_number) # Check if the decimal number is zero: further we will convert it till the number is zero if decimal_number == 0: # 0 in the octal numeral system is the representation of 0 in decimal one, so we append 0 to the list of the octal numbers octal_number.append(str(0)) #otherwise else: # The loop executes till the number is zero while decimal_number != 0: # Counting the remainder of dividing by eight remainder = decimal_number % 8 # Appending the converted remainder for creating an octal representation octal_number.append(str(remainder)) # This operation allows to decrease number eight times and work with the integer part of new one decimal_number = decimal_number//8 # Reversing the string octal_number = octal_number[::-1] # Joining all items of the string to make it more readable octal_number = " ".join(octal_number) # Printing the result print("The number in octal numeral system is:", octal_number)
Завдання
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.