Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Conheça o Sistema Numérico Octal | Sistema Numérico Octal
Sistemas de Numeração 101

book
Conheça o Sistema Numérico Octal

Existe outro sistema numérico chamado octal. Em comparação com o binário ou decimal, ele é composto por 8 dígitos, começando com zero: 0,1,2,3,4,5,6,7.

Se você está se perguntando por que foi implementado, eu quero esclarecer algo.

Uso

Como você lembra, o número em representação binária consiste em vários dígitos, um bit para cada um deles; mas em um sistema numeral octal, três dígitos binários representam um octal. Portanto, você pode representar uma palavra para o computador usando menos símbolos. Enormes sequências de código binário podem ser representadas de maneira mais bela para o computador; assim, menos memória é preenchida. O princípio de converter um número para o sistema decimal a partir do octal é o mesmo que com binário:

Regra

Os algoritmos de conversão para o sistema numeral decimal se sobrepõem para diferentes sistemas numéricos. Aqui está o mesmo para o número octal 221: o índice do número 2 à esquerda é 2, o índice do número 2 do meio é 1 e o índice do número 1 é zero; mas aqui devemos multiplicar os números por 8 elevado ao índice correspondente. Assim, 221 -> 2*8^2 + 2*8^1 + 1*8^0 = 128 + 16 + 1 = 145.

# Defining the octal number
octal_number = 221
# Creating a variable for storing the converted decimal number
decimal_number = 0
# The text should be realised here due to the reason that further the binary number will be changed
print("The number in octal numeral system is: ", octal_number)
# Creating value for working with the power of a number
power = 0
# The loop executes till the number is not null
while octal_number != 0:
# Separating the last digit of octal_number using the remainder of the division operation
last_digit = octal_number % 10
# Multiply last_digit by 8 raised to the relevant power
result = last_digit * pow(8, power)
# Adding the result to the decimal number
decimal_number = decimal_number + result
# This operation of integer division decreases a number and put aside the last digit that was already used
octal_number = octal_number // 10
# Increasing iterator to work with the power
power = power + 1
# Printing the result
print("The number in decimal numeral system is: ", decimal_number)
12345678910111213141516171819202122
# Defining the octal number octal_number = 221 # Creating a variable for storing the converted decimal number decimal_number = 0 # The text should be realised here due to the reason that further the binary number will be changed print("The number in octal numeral system is: ", octal_number) # Creating value for working with the power of a number power = 0 # The loop executes till the number is not null while octal_number != 0: # Separating the last digit of octal_number using the remainder of the division operation last_digit = octal_number % 10 # Multiply last_digit by 8 raised to the relevant power result = last_digit * pow(8, power) # Adding the result to the decimal number decimal_number = decimal_number + result # This operation of integer division decreases a number and put aside the last digit that was already used octal_number = octal_number // 10 # Increasing iterator to work with the power power = power + 1 # Printing the result print("The number in decimal numeral system is: ", decimal_number)
copy
Tarefa

Swipe to start coding

Fazer o máximo de tarefas possível é a receita para o sucesso! Escreva o código que irá decodificar o número 117 do sistema numeral octal para decimal. Preencha as lacunas e siga o algoritmo. Se tudo estiver correto, você receberá um número especial 🧐 Mas a explicação está esperando por você no final deste capítulo.

  1. Imprima o octal_number.
  2. Defina o laço que percorre a variável octal_number até que ela seja zero.
  3. Atribua o resto da divisão de octal_number por 10 à variável last_digit.
  4. Multiplique o last_digit recebido por 8 elevado ao poder relevante.
  5. Diminua o octal_number usando a divisão inteira por 10.
  6. Aumente o power em 1.
  7. Imprima o decimal_number.

Solução

octal_number = 427011
decimal_number = 0
print("The number in octal numeral system is:", octal_number)
power = 0
while octal_number != 0:
last_digit = octal_number % 10
result = last_digit * pow(8, power)
decimal_number = decimal_number + result
octal_number = octal_number // 10
power = power + 1
print("The number in decimal numeral system is:", decimal_number)

Nota

Acredito que você recebeu 142857, que é chamado de número cíclico. Deixe-me explicar o porquê: 142857 x 1 = 142857 142857 x 2 = 285714 142857 x 3 = 428571 142857 x 4 = 571428 142857 x 5 = 714285 142857 x 6 = 857142. Como você pode reconhecer, tal multiplicação resulta em um novo número que é o mesmo, mas com os dígitos localizados em uma ordem diferente; isso cria um ciclo. Aqui vai outro fato interessante para você🙄.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 1
octal_number = 427011
decimal_number = 0
# Output the octal number
___("The number in octal numeral system is: ", ___)
power = 0
# Define the loop which goes through the octal_number variable till it is zero
while ______:
# Assign the remainder of division octal_number by ten to the variable last_digit
last_digit = ___
# Multiply the received last_digit by the 8 raised to the relevant power
result = ___
decimal_number = decimal_number + result
# Decrease the octal number using integer division by 10
octal_number = ___ ___
# Increase the power by 1
___
# Output the decimal number
print("The number in decimal numeral system is: ", ___)

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt