Given a number and we have to find total number of bits of binary value to represent the number using Python.
Example:
Input:
num = 61
Binary value of 61 is = 0b111101
Output:
Total number of bits = 6
Note: '0b' is prefixed to represent binary value
Input:
num = 12
Binary value of 61 is = 0b1100
Output:
Total number of bits = 4
Program:
Output
By defining function
In the below program, we used len(bin(n)[2:]), it will return total length of the binary value after 2 characters.
Let’s understand
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer