> ## Content Index
> Fetch the complete content index at: https://www.javahandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Challenge 1: Get the First Set Bit Position Using the Left Shift
- URL: https://www.javahandbook.com/bitmask/challenge-1-get-the-first-set-bit-position-using-the-left-shift/
- Published: 2025-08-30T05:28:00.000Z
- Updated: 2026-02-14T07:54:24.000Z
- Author: Gopi Gorantala
- Tags: #docs, Left Shift Problems, #bitmask

This problem is similar to the last lesson we discussed. If you need a clue, return to the previous lesson to further your understanding.

## Introduction

In this question, we need to find the first set-bit position from the right.

## Problem statement

Given an input number, find the first set-bit position of the number.

```json
Input: n = 18 

Output: 2
```

## Coding exercise

This problem is designed for your practice, so try to solve it yourself first. You can always refer to the solution in the next lesson if you get stuck. Good luck!

> **Hint:** Use the previous logic we discussed to solve this.

```java
// java
// TODO: finish the challenge or check next lesson for solution
class Solution {
    public static int getFirstSetBitPos(int n) {
        // Write - Your - Code- Here
        
        return -1; // change this and return the position of the first set-bit.
    }
}
```

```py
# Python
# TODO: finish the challenge or check next lesson for solution

def getFirstSetBitPos(n):
	# Write - Your - Code- Here
        
    return -1 # change this and return the position of the first set-bit.
```

```js
// javascript
// TODO: finish the challenge or check next lesson for solution
const getFirstSetBitPos = n => {
    // Write - Your - Code- Here

    return -1; // change this and return the position of the first set-bit.
}
```

```cpp
// javascript
// TODO: finish the challenge or check next lesson for solution
#include <iostream>
using namespace std;

int getFirstSetbit(int n) {
  // Write - Your - Code- Here

  return -1; // change this and return the position of the first set-bit.
}
```

```ts
// typescript
// TODO: finish the challenge or check next lesson for solution
export const getFirstSetBitPos = (n: number): number => {
    // Write - Your - Code- Here

    return -1; // change this and return the position of the first set-bit.
}
```

The solution will be explained in the next lesson.