mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] Utility.Bit
[+] Utility.Bit
This commit is contained in:
61
Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs
Normal file
61
Assets/TEngine/Runtime/GameFramework/Utility/Utility.Bit.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace TEngine
|
||||
{
|
||||
public static partial class Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 位运算相关的实用函数。
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95d9fac2a8ff467e864aab4cd2650dfc
|
||||
timeCreated: 1682352897
|
Reference in New Issue
Block a user