0
while((number & 1) == 0) {
   number >>>= 1;
}

I don't quite understand the condition in while loop, and what does it represent '>>>='.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • Take a look at duplicates at top of your question (you may need to refresh this page to see them). Also this may interest you: https://stackoverflow.com/a/14923514/1393766 – Pshemo Aug 04 '17 at 19:42

1 Answers1

2

The condition in the while loop tests whether the lowest bit of number is zero.

The >>>= operator is a compound assignment operator (see the tutorial here). The statement is the same as:

number = number >>> 1;

The >>> operator is a bit-wise right-shift with zero fill (see here). It differs from >> in that >> will fill with the sign bit, while >>> always fills with zero.

Note that the code fragment you posted will never terminate if number starts out as 0.

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521