Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Write the Code in One Line | Revelation
Numeral Systems 101

Sveip for å vise menyen

book
Write the Code in One Line

I strongly believe that Python is a careful language; hence, it tries to make your life effortless and forces you to get rid of the habit to program using another language😏.

bin helps you without any loops convert the number to a binary representation.

1234
decimal_number = 9874 binary_number = bin(decimal_number) print(binary_number)
copy

Indeed, python cares about us, and I suppose we should appreciate it and allow it to care about itself.

  • 0b is a sign for Python that this code is binary;

  • 0o or 0O(both ways are acceptable) means that this code is octal;

  • 0X defines hexadecimal code in the way that we learned (with uppercase letters), by the way, there is also a 0x format, but it defines hexadecimal code in lowercase letters.

Therefore, the code in each system is determined after 0b, 0c or 0X, except decimal obviously.

oct will come in handy when you want to cipher numbers to the octal numeral system.

1234
decimal_number = 25 octal_number = oct(decimal_number) print(octal_number)
copy

hex is valuable when you want to convert a number to a hexadecimal numeral system.

1234
decimal_number = 1390 hexadecimal_number = hex(decimal_number) print(hexadecimal_number)
copy
Oppgave

Swipe to start coding

So far so good ☺️. Here you should convert a number from a decimal numeral system to another that you've learned.Follow this algorithm:

  1. Convert the decimal_number to the binary numeral system.
  2. Convert the decimal_number to the octal numeral system.
  3. Convert decimal_number to the hexadecimal numeral system.
  4. Print the result.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 1

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

book
Write the Code in One Line

I strongly believe that Python is a careful language; hence, it tries to make your life effortless and forces you to get rid of the habit to program using another language😏.

bin helps you without any loops convert the number to a binary representation.

1234
decimal_number = 9874 binary_number = bin(decimal_number) print(binary_number)
copy

Indeed, python cares about us, and I suppose we should appreciate it and allow it to care about itself.

  • 0b is a sign for Python that this code is binary;

  • 0o or 0O(both ways are acceptable) means that this code is octal;

  • 0X defines hexadecimal code in the way that we learned (with uppercase letters), by the way, there is also a 0x format, but it defines hexadecimal code in lowercase letters.

Therefore, the code in each system is determined after 0b, 0c or 0X, except decimal obviously.

oct will come in handy when you want to cipher numbers to the octal numeral system.

1234
decimal_number = 25 octal_number = oct(decimal_number) print(octal_number)
copy

hex is valuable when you want to convert a number to a hexadecimal numeral system.

1234
decimal_number = 1390 hexadecimal_number = hex(decimal_number) print(hexadecimal_number)
copy
Oppgave

Swipe to start coding

So far so good ☺️. Here you should convert a number from a decimal numeral system to another that you've learned.Follow this algorithm:

  1. Convert the decimal_number to the binary numeral system.
  2. Convert the decimal_number to the octal numeral system.
  3. Convert decimal_number to the hexadecimal numeral system.
  4. Print the result.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 4. Kapittel 1
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt