Question: Problem 2: Logs and Binary Representation (10 pts) Recall that the logarithm base b of a number y is the power x such that b

Problem 2: Logs and Binary Representation (10 pts)

Recall that the logarithm base b of a number y is the power x such that b x = y. For example, the log base 10 of 100 (denoted l o g 10 100 and computed math.log10(100) in Python) is the power we need to take 10 to in order to get 100. This is 2, since 10 2 = 100. Also recall that

l o g b y = l o g 10 y l o g 10 b

for any base b. If we have 3 bits then we can represent at most 2 3 = 8 distinct values. This is because each of the 3 bits can either be 0 or 1 so there are 2 choices for each bit resulting in a total of 2 3 = 8 different binary strings of length 3: 000, 001, 010, 011, 100, 101, 110, 111.

For this problem you will write a function numBits() in Python that takes one parameter, the number of distinct values we wish to represent and returns the number of bits you will need. For example, numBits(8) should return 3. Your function should use the log10() function from the math module. Note that there is no such thing as a fraction of a bit, so you shouldnt give a number of bits with a fractional part. You may want to use the math.ceil() or math.floor() functions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!