4 added 6 characters in body
source | link

C (gcc), 51 48 4141 40 bytes

i;f(n){for(i=0;n;n/=2)n&1?++i:-i+=n%2*2-i;n=i>0;1;n=i>0;}

Try it online!Try it online!

C (gcc), 51 48 41 bytes

i;f(n){for(i=0;n;n/=2)n&1?++i:--i;n=i>0;}

Try it online!

C (gcc), 51 48 41 40 bytes

i;f(n){for(i=0;n;n/=2)i+=n%2*2-1;n=i>0;}

Try it online!

3 deleted 2 characters in body
source | link

C (gcc), 51 4848 41 bytes

i;f(n){for(i=0;n&&n^-1;n>>=1i=0;n;n/=2)n&1?++i:--i;n=i>0;}

Try it online!Try it online!

C (gcc), 51 48 bytes

i;f(n){for(i=0;n&&n^-1;n>>=1)n&1?++i:--i;n=i>0;}

Try it online!

C (gcc), 51 48 41 bytes

i;f(n){for(i=0;n;n/=2)n&1?++i:--i;n=i>0;}

Try it online!

2 added 1 character in body
source | link

C (gcc), 5151 48 bytes

i;f(unsigned n){for(i=0;n;n>>=1i=0;n&&n^-1;n>>=1)n&1?++i:--i;n=i>0;}

Try it online!Try it online!

C (gcc), 51 bytes

i;f(unsigned n){for(i=0;n;n>>=1)n&1?++i:--i;n=i>0;}

Try it online!

C (gcc), 51 48 bytes

i;f(n){for(i=0;n&&n^-1;n>>=1)n&1?++i:--i;n=i>0;}

Try it online!

1
source | link