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 **2 ^{N – 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; ` `} ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

## 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 ` |

*chevron_right*

*filter_none*

**Output:**

8

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Count numbers having N 0's and and M 1's with no leading zeros
- Comparing leading zeros in binary representations of two numbers
- All possible numbers of N digits and base B without leading zeros
- Number of leading zeros in binary representation of a given number
- Remove leading zeros from a Number given as a string
- C program to count zeros and ones in binary representation of a number
- Count unique numbers that can be generated from N by adding one and removing trailing zeros
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count numbers have all 1s together in binary representation
- Count of Binary Digit numbers smaller than N
- Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*..
- Count number of trailing zeros in product of array
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- Minimum count of Full Binary Trees such that the count of leaves is N
- Count of binary strings of length N having equal count of 0's and 1's
- Count of binary strings of length N with even set bit count and at most K consecutive 1s
- Count of numbers upto M divisible by given Prime Numbers
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count numbers which are divisible by all the numbers from 2 to 10
- Count numbers which can be constructed using two numbers

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.