# Python: Program to Count Total Number of Bits in Number

python program to count total number of bits in a number; In this tutorial, you will learn how to count total number of bits in the number using Python.

## Python program to count total number of bits in a number

Follow the below steps and count the total number of the binary representations of each number in python program; as shown below:

• Take input number from user.
• Find total number of bit to a given number using bit() function.
• Print the result.
```# write a python program to count total number of bits in a number

num = int(input("Please Enter any Number: "))

# use bin () method to get the binary value of a number
# print binary value output will be 0b111101
print ("binary value of {0} is: {1}".format(num, bin(num)))

# store the length of the binary number
length = len(bin(num))

# to get exact length total number of bits
# subtract 2 from the length
length -=2

# print length
print ("total number of bits: ", length)

```

Output

```Please Enter any Number:  13
binary value of 13 is: 0b1101
total number of bits:  4 ```

### Recommended Python Programs 