PYTHON 5 lines, no need bit manipulation, just math
\ndigit, num = 1, N\nwhile N > 1:\n\tdigit += 1\n\tN = N//2\nreturn 2**digit - 1 - num\n
```\ndigit, num = 1, N\nwhile N > 1:\n\tdigit += 1\n\tN = N//2\nreturn 2**digit - 1 - num\n```
[]