Binary Countdown Length inspired by Count down from infinity

Given a non-negative integer N, output the number of repetitions of the following steps it takes to reach 0:


Convert N to binary (4812390 -&gt; 10010010110111001100110)
Flip each bit (10010010110111001100110 -&gt; 01101101001000110011001)
Trim leading zeroes (01101101001000110011001 -&gt; 1101101001000110011001)
Convert back to decimal (1101101001000110011001 -&gt; 3576217)


Rules


Input and output may be in any unambiguous, consistent format
The input will be within the native representable integer range for your language (if your language supports arbitrarily-large integers, there is no bound)


Test Cases

0 -&gt; 0
1 -&gt; 1
42 -&gt; 6
97 -&gt; 3
170 -&gt; 8
255 -&gt; 1
682 -&gt; 10
8675309 -&gt; 11
4812390 -&gt; 14
178956970 -&gt; 28
2863311530 -&gt; 32




This sequence is A005811 in the OEIS.
Jelly, 6 4 bytes

^HBS


Try it online! or verify all test cases.

Background

Let n be a non-negative integer.

Steps 2 and 3 of the process described in the spec can alternatively be stated as removing all leading 1's and toggling the remaining bits. 

This means that we'll remove exactly one group of adjacent and equal binary digits in each iteration, so the Binary Countdown Length of n is just the number of these groups in the binary representation of n. For the purposes of this challenge, think of 0 as having no digits.

For n = 8675309, the process looks as follows in binary.

100001000101111111101101
 11110111010000000010010
     1000101111111101101
      111010000000010010
         101111111101101
          10000000010010
           1111111101101
                   10010
                    1101
                      10
                       1
                       0


Instead of counting these groups (which would fail for edge case 0), we do the following.

n and n:2 have the following binary representations.

n   = 8675309 = 100001000101111111101101_2
n:2 = 4337654 =  10000100010111111110110_2


Note that n:2's binary representation is simply n's, shifted one bit to the left.

If we XOR n and n:2, we'll obtain a 1 (MSB), and an additional 1 for each pair of different adjacent digits. The number of groups is thus equal to the number of set bits in n ⊻ n:2.

How it works

^HBS  Main link. Argument: n

 H    Halve; yield n:2.
^     XOR n with n:2.
  B   Convert the result to binary.
   S  Compute the sum of the resulting binary digits.