0

Aside from using f-string formatting in python to get a binary string from a number, such as:

>>> "{0:>08b}".format(i)
'00001100'

What would be the simplest functional/algorithmic way to get the binary representation of a number? For example, what I'm using now is:

def number_to_binary(number, s=''):
    while (number):
        s = str(number % 2) + s
        number = number >> 1
    return s
samuelbrody1249
  • 4,379
  • 1
  • 15
  • 58

0 Answers0