int addDigits(int num)

{

return(-(~((num-1)%9)));

}

eg:-

x = 2 (0010),

~x = ~2 = 1101 (13 numerical)

-~x = -1101

Interpreting bits 1101 in 2’s complement form yields numerical value as -(2^4 – 13) = -3. Applying ‘-‘ on the result leaves 3.

1+(n-1)%9 gives 6ms

(-(~((num-1)%9))) gives 4ms