fork(4) download
  1. using System;
  2.  
  3. public static class Extensions
  4. {
  5. public static int HighestOneBit(this int number)
  6. {
  7. return (int)Math.Pow(2, Convert.ToString(number, 2).Length - 1);
  8. }
  9. }
  10.  
  11.  
  12. public class Test
  13. {
  14. public static uint highestOneBit(uint i)
  15. {
  16. i |= (i >> 1);
  17. i |= (i >> 2);
  18. i |= (i >> 4);
  19. i |= (i >> 8);
  20. return i - (i >> 1);
  21. }
  22.  
  23. public static void Main()
  24. {
  25. Console.WriteLine();
  26. Console.WriteLine((-1).ToString("X"));
  27. Console.WriteLine((Int32.MinValue).HighestOneBit().ToString("X"));
  28. }
  29. }
Success #stdin #stdout 0.04s 24208KB
stdin
Standard input is empty
stdout
FFFFFFFF
80000000