# Find first and last set bit of a long integer

Sidef has arbitrary sized integers.

```ruby
func msb(n) {
    var b = 0
    while(n >>= 1) { ++b }
    return b
}
 
func lsb(n) {
    msb(n & -n)
}
```

Test cases:

```ruby
func table (base,power) {
    var digits = length(base**power)
    printf("%#{digits}s  lsb msb\n", 'number')
    for n in (0..power) {
        var x = base**n
        printf("%#{digits}s  %2s  %3s\n", x, lsb(x), msb(x))
    }
}
 
table(42, 20)
table(1302, 20)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/f/find_first_and_last_set_bit_of_a_long_integer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
