if (b < pow(2, i))

Using "pow" is a sledgehammer to miss a nut.

Thank you AWOL, I appreciate you very much, but ...

can you say

**is a sledgehammer to miss a nut** in other words I can understand?

(Sorry, I am just a 'foreigner')

The more usual cliche is "take a sledgehammer to crack a nut", meaning to use an inappropriately heavy-handed method to solve a trivial problem.

However here, using "pow()" to calculate powers of two is the sledgehammer that will not hit the nut, as I shall now demonstrate :

void setup ()

{

Serial.begin (115200);

for (int i = 0; i < 32; i++)

{

uint32_t x = pow (2, i);

uint32_t y = 1UL << i;

if (x != y)

{

Serial.print ("Oops ! i = ");

Serial.print (i);

Serial.print (", x = ");

Serial.print (x);

Serial.print (", y = ");

Serial.println (y);

}

}

}

void loop ()

{}

Oops ! i = 2, x = 3, y = 4

Oops ! i = 3, x = 7, y = 8

Oops ! i = 4, x = 15, y = 16

Oops ! i = 5, x = 31, y = 32

Oops ! i = 6, x = 63, y = 64

Oops ! i = 7, x = 127, y = 128

Oops ! i = 8, x = 255, y = 256

Oops ! i = 9, x = 511, y = 512

Oops ! i = 10, x = 1023, y = 1024

Oops ! i = 11, x = 2047, y = 2048

Oops ! i = 12, x = 4095, y = 4096

Oops ! i = 14, x = 16383, y = 16384

Oops ! i = 15, x = 32767, y = 32768

Oops ! i = 16, x = 65535, y = 65536

Oops ! i = 18, x = 262143, y = 262144

Oops ! i = 19, x = 524287, y = 524288

Oops ! i = 20, x = 1048574, y = 1048576

Oops ! i = 22, x = 4194298, y = 4194304

Oops ! i = 23, x = 8388597, y = 8388608

Oops ! i = 24, x = 16777194, y = 16777216

Oops ! i = 27, x = 134217552, y = 134217728

Oops ! i = 28, x = 268435104, y = 268435456

Oops ! i = 30, x = 1073740416, y = 1073741824

Oops ! i = 31, x = 2147480832, y = 2147483648

(Sorry, I am just a 'foreigner')

Hey! Me too!