diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs new file mode 100644 index 00000000..9f3d795b --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs @@ -0,0 +1,61 @@ +namespace TEngine +{ + public static partial class Utility + { + /// + /// 位运算相关的实用函数。 + /// + public static class Bit + { + public static bool HasBit(long val, int idx) + { + return (val & 1L << idx) != 0L; + } + + public static void SetBit(ref long val, int idx, bool isSet) + { + if (isSet) + { + val |= (1L << idx); + } + else + { + val &= ~(1L << idx); + } + } + + public static bool HasBit(int val, int idx) + { + return (val & 1 << idx) != 0; + } + + + public static void SetBit(ref int val, int idx, bool isSet) + { + if (isSet) + { + val |= (1 << idx); + } + else + { + val &= ~(1 << idx); + } + } + + public static bool HasBit(byte val, byte idx) + { + return (val & 1 << idx) != 0; + } + + public static void SetBit(ref byte val, byte idx) + { + val |= (byte)(1 << idx); + } + + public static byte ToByte(byte idx) + { + return (byte)(1 << idx); + } + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta new file mode 100644 index 00000000..8a0d12a1 --- /dev/null +++ b/Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 95d9fac2a8ff467e864aab4cd2650dfc +timeCreated: 1682352897 \ No newline at end of file