Number to binary

OSCC · Python, Math · Oct 7, 2020

Returns the binary representation of the given number.

  • Use bin() to convert a given decimal number into its binary equivalent.
def to_binary(n):
  return bin(n)
to_binary(100) # 0b1100100

Recommended snippets

  • Number to hex

    Python, Math

    Returns the hexadecimal representation of the given number.

  • Generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit.

  • Number in range

    Python, Math

    Checks if the given number falls within the given range.