using System; using System.Collections; using System.Collections.Generic; namespace HeavenStudio.Util { public static class BitwiseUtils { /// /// Returns the value of the lowest set bit in the given integer. /// /// The integer to check. public static int FirstSetBit(int num) { return num & (-num); } /// /// Returns true if the wanted bit is set in the given integer. /// /// The integer to check. /// The bit(s) to check for. public static bool WantCurrent(int num, int want) { return (num & want) == want; } /// /// Returns true if the wanted bit is set in the first integer, and not in the second. /// /// The first integer to check. /// The second integer to check. /// The bit(s) to check for. public static bool WantCurrentAndNotLast(int num1, int num2, int want) { return ((num1 & want) == want) && ((num2 & want) != want); } /// /// Returns true if the wanted bit is not set in the first integer, but set in the second. /// /// The first integer to check. /// The second integer to check. /// The bit(s) to check for. public static bool WantNotCurrentAndLast(int num1, int num2, int want) { return ((num1 & want) != want) && ((num2 & want) == want); } } }