how to find the left most bit 1 in binary of any number

#include <iostream>

int findLeftmostSetBit(int n) {
    if (n == 0)
        return -1;

    int position = 0;
    while ((n & 1) == 0) {
        n = n >> 1;
        ++position;
    }

    return position + 1;
}

int main() {
    int num;
    std::cout << "Enter a number: ";
    std::cin >> num;

    int result = findLeftmostSetBit(num);

    if (result == -1)
        std::cout << "There are no set bits in the binary representation of 0." << std::endl;
    else
        std::cout << "The position of the leftmost set bit in the binary representation is: " << result << std::endl;

    return 0;
}