Given a positive number n, count total bit in it.

**Examples: **

Input : 13 Output : 4 Binary representation of 13 is 1101 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.

## Python3

`# Function to count total bits in a number` `def` `countTotalBits(num):` ` ` ` ` `# convert number into it's binary and ` ` ` `# remove first two characters 0b.` ` ` `binary ` `=` `bin` `(num)[` `2` `:]` ` ` `print` `(` `len` `(binary)) ` `# Driver program` `if` `__name__ ` `=` `=` `"__main__"` `:` ` ` `num ` `=` `13` ` ` `countTotalBits(num)` |

*chevron_right*

*filter_none*

**Output: **

4

## Recommended Posts:

- bin() in Python
- Python map function | Count total set bits in all numbers from 1 to n
- Python VLC MediaList - Getting Total Count of Media
- Python IMDbPY – Total number of seasons from episodes info-set of the series
- Python IMDbPY – Total number of episode of each season of the series
- Count set bits using Python List comprehension
- Python | Count unset bits in a range
- Python | Count set bits in a range
- Minimize the total number of teddies to be distributed
- Python | Get total keys in dictionary
- Python | Percentage increase in the total surface area of the cuboid
- Python - Sort Tuples by Total digits
- Python - Sort Matrix by total characters
- Reverse bits of a positive integer number in Python
- Make A, B and C equal by adding total value N to them
- Find length of one array element in bytes and total bytes consumed by the elements in Numpy
- Program to find the Nth natural number with exactly two bits set
- Python Slicing | Extract ‘k’ bits from a given position
- Different ways to Invert the Binary bits in Python
- Python program to count number of vowels using sets in given string

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.