Given a positive number n, count total bit in it.
Input : 13 Output : 4 Binary representation of 13 is 1001 Input : 183 Output : 8 Input : 4096 Output : 13
We have existing solution for this problem please refer Count total bits in a number link. We can solve this problem quickly in Python using bin() function. Convert number into it’s binary using bin() function and remove starting two characters ‘0b’ of output binary string because bin function appends ‘0b’ as prefix in output string. Now print length of binary string that will be the count of bits in binary representation of input number.
- Python map function | Count total set bits in all numbers from 1 to n
- Python | Count set bits in a range
- Count set bits using Python List comprehension
- Python | Count unset bits in a range
- Reverse bits of a positive integer number in Python
- Python | Ways to count number of substring in string
- Count number of lines in a text file in Python
- Python | Count number of items in a dictionary value that is a list
- Python | Get total keys in dictionary
- Python program to count number of vowels using sets in given string
- Python | Count the Number of matching characters in a pair of string
- Python program to Count the Number of occurrences of a key-value pair in a text file
- Minimize the total number of teddies to be distributed
- Python | Percentage increase in the total surface area of the cuboid
- Python Slicing | Extract ‘k’ bits from a given position
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.