Count of N-bit binary numbers without leading zeros Last Updated : 10 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an integer N, the task is to find the count of N-bit binary numbers without leading zeros.Examples: Input: N = 2 Output: 2 10 and 11 are the only possible binary numbers.Input: N = 4 Output: 8 Approach: Since the numbers cannot have leading zeros so the left-most bit has to be set to 1. Now for the rest of the N - 1 bits, there are two choices they can either be set to 0 or 1. So, the count of possible numbers will be 2N - 1.Below is the implementation of the above approach: C++ // C++ implementation of the approach #include <bits/stdc++.h> using namespace std; // Function to return the count // of possible numbers int count(int n) { return pow(2, n - 1); } // Driver code int main() { int n = 4; cout << count(n); return 0; } Java // Java implementation of the approach class GFG { // Function to return the count // of possible numbers static int count(int n) { return (int)Math.pow(2, n - 1); } // Driver code public static void main (String[] args) { int n = 4; System.out.println(count(n)); } } // This code is contributed by AnkitRai01 Python3 # Python3 implementation of the approach # Function to return the count # of possible numbers def count(n): return pow(2, n - 1) # Driver code n = 4 print(count(n)) # This code is contributed by mohit kumar C# // C# implementation of the approach using System; class GFG { // Function to return the count // of possible numbers static int count(int n) { return (int)Math.Pow(2, n - 1); } // Driver code public static void Main (String[] args) { int n = 4; Console.WriteLine(count(n)); } } // This code is contributed by 29AjayKumar JavaScript <script> // JavaScript implementation of the approach // Function to return the count // of possible numbers function count(n) { return Math.pow(2, n - 1); } // Driver code var n = 4; document.write(count(n)); </script> Output: 8 Time Complexity: O(log n) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Comparing leading zeros in binary representations of two numbers S spp____ Follow Improve Article Tags : Bit Magic Mathematical DSA Numbers Practice Tags : Bit MagicMathematicalNumbers Similar Reads Count numbers less than N whose Bitwise AND with N is zero Given a positive integer N, the task is to count all numbers which are less than N, whose Bitwise AND of all such numbers with N is zero. Examples: Input: N = 5Output: 2Explanation: The integers less than N(= 5) whose Bitwise AND with 5 is 0 are 0 and 2. Hence, the total count is 2. Input: N = 9Outp 8 min read Comparing leading zeros in binary representations of two numbers Given two integer numbers x and y. Compare and print which one of them has more leading zeros using Bitwise operation. If both the no. have the same no. of leading zeros, print "Equal".Note:- A leading zero is any 0 digit that comes before the first nonzero digit in the binary notation of the number 8 min read Count of Binary Digit numbers smaller than N Given a limit N, we need to find out the count of binary digit numbers which are smaller than N. Binary digit numbers are those numbers that contain only 0 and 1 as their digits, like 1, 10, 101, etc are binary digit numbers. Examples: Input : N = 200 Output : 7 Count of binary digit number smaller 6 min read Number of leading zeros in binary representation of a given number Given a positive integer N, the task is to find the number of leading zeros in its binary representation.A leading zero is any 0 digit that comes before the first nonzero digit in a number's binary form. Examples: Input : N = 16Output : 27Explanation: As Binary(16) = (0000000000000000000000000001000 10 min read Count of N-digit numbers in base K with no two consecutive zeroes Given two integers N and K, the task is to find the count of all the integer in base K which satisfy the following conditions: The integers must be of exactly N digits.There should be no leading 0.There must not be any consecutive digit pair such that both the digits are 0.Examples: Input: N = 3, K 15+ min read Python Bin | Count total bits in a number 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. Approach#1: We can solve this problem quick 3 min read Like