Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BitUtility.cs 1015B

12345678910111213141516171819202122232425262728
  1. using System;
  2. namespace UnityEditor.TestTools.TestRunner.GUI.Controls
  3. {
  4. /// <summary>
  5. /// Provides methods for dealing with common bit operations.
  6. /// </summary>
  7. internal static class BitUtility
  8. {
  9. /// <summary>
  10. /// Evaluates the cardinality of an integer, treating the value as a bit set.
  11. /// Optimization based on http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel.
  12. /// </summary>
  13. /// <param name="integer">The input integer value.</param>
  14. /// <returns>The number of bits set in the provided input integer value.</returns>
  15. internal static int GetCardinality(int integer)
  16. {
  17. unchecked
  18. {
  19. integer = integer - ((integer >> 1) & 0x55555555);
  20. integer = (integer & 0x33333333) + ((integer >> 2) & 0x33333333);
  21. integer = (((integer + (integer >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
  22. }
  23. return integer;
  24. }
  25. }
  26. }