smallestButton function Null safety

int smallestButton(
  1. int buttons
)

Returns the button of buttons with the smallest integer.

The buttons parameter is a bit field where each set bit represents a button. This function returns the set bit closest to the least significant bit.

It returns zero when buttons is zero.

Example:

  assert(rightmostButton(0x1) == 0x1);
  assert(rightmostButton(0x11) == 0x1);
  assert(rightmostButton(0) == 0);

See also:

  • isSingleButton, which checks if a buttons contains exactly one button.

Implementation

int smallestButton(int buttons) => buttons & (-buttons);