We can represent numbers in different bases think of how


We can represent numbers in different bases. Think of how you could represent the number 5 in base 2. Essentially, how can you break the number 5 into powers of 2. It contains one 4 and one 1. In base 2, your digit overflows after 1, so this representation of numbers only has 1 and 0.

5 = 1 * 2^2 + 0 * 2^1 + 1 * 2^0

This function takes a number and returns a list of it's representation in base 2.

def binary(n):
"""Return a list representing the representation of a number in base 2.

>>> binary(55055)
[1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1]
>>> binary(-136)
['-', 1, 0, 0, 0, 1, 0, 0, 0]
"""

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: We can represent numbers in different bases think of how
Reference No:- TGS02927512

Now Priced at $10 (50% Discount)

Recommended (90%)

Rated (4.3/5)