darrellp

CountSteps

Nov 25th, 2021
552
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int CountSteps(int n)
  2. {
  3.     if (n <= 0)
  4.     {
  5.         return 0;
  6.     }
  7.    
  8.     int ret = 0;
  9.     while (n != 1)
  10.     {
  11.         ret += 1 + (n & 1);
  12.         n >>= 1;
  13.     }
  14.     return ret + 1;
  15. }
RAW Paste Data