#include <Arduino.h>

int findFirstOneBitPosition(unsigned int n)
{
  // Step 1: Isolate the first 1 bit from the right
  unsigned int isolatedBit = n & -n;

  // Step 2: Find the position of the isolated bit (1-based index)
  int position = log(isolatedBit) / log(2) + 1;

  return position;
}

void setup() {
  // Initialize serial communication at 9600 bits per second
  Serial.begin(9600);

  // Example binary number
  unsigned int binaryNumber = 0b1011010;
  
  // Find the position of the first 1 bit from the right
  int position = findFirstOneBitPosition(binaryNumber);

  // Print the position
  Serial.print("The position of the first 1 bit (from the right) is: ");
  Serial.println(position);
}

void loop()
{
  // Nothing to do here
}