2025-01-08 18:46:17 +00:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
|
|
|
public class BitMath
|
|
|
|
{
|
|
|
|
public static int GetInt32BitMask( int bit )
|
|
|
|
{
|
|
|
|
return ( 1 << bit );
|
|
|
|
}
|
|
|
|
|
2025-04-29 19:46:45 +00:00
|
|
|
public static long GetInt64BitMask( int bit )
|
|
|
|
{
|
|
|
|
return ( 1 << bit );
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
public static int SetBit( int value, int bitPosition )
|
|
|
|
{
|
|
|
|
return value | GetInt32BitMask( bitPosition );
|
|
|
|
}
|
|
|
|
|
2025-04-29 19:46:45 +00:00
|
|
|
public static long SetBit( long value, int bitPosition )
|
|
|
|
{
|
|
|
|
return value | GetInt64BitMask( bitPosition );
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
public static int UnsetBit( int value, int bitPosition )
|
|
|
|
{
|
|
|
|
return value & ~GetInt32BitMask( bitPosition );
|
|
|
|
}
|
|
|
|
|
2025-04-29 19:46:45 +00:00
|
|
|
public static long UnsetBit( long value, int bitPosition )
|
|
|
|
{
|
|
|
|
return value & ~GetInt64BitMask( bitPosition );
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
public static bool IsBitSet( int value, int bitPosition )
|
|
|
|
{
|
|
|
|
var mask = GetInt32BitMask( bitPosition );
|
|
|
|
return ( value & mask ) == mask;
|
|
|
|
}
|
|
|
|
|
2025-04-29 19:46:45 +00:00
|
|
|
public static bool IsBitSet( long value, int bitPosition )
|
|
|
|
{
|
|
|
|
var mask = GetInt64BitMask( bitPosition );
|
|
|
|
return ( value & mask ) == mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsMaskSet( int value, int mask )
|
|
|
|
{
|
|
|
|
return ( value & mask ) == mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsMaskSet( long value, long mask )
|
|
|
|
{
|
|
|
|
return ( value & mask ) == mask;
|
|
|
|
}
|
2025-01-08 18:46:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|