To flip the number, we should

- Get the complement of the 32-bit positive(which means unsigned) number

```
var com = ~num >>> 0;
```

- Find out how many bits you should keep

```
var len = num.toString(2).length;
```

- Left shift 32-len bits to remove all the 1, and move back the result bits

```
return ((com << (32-len)) >>> (32-len));
```

Note that `>>>`

means shift the number without sign bit so we won't get negative result

ex: input = 5 (101)

- com = 11111111 11111111 11111111 11111010
- len = 3
- com << 27 = 010 000...... com >>> 27 = 00000000 00000000 00000000 00000010