diff --git a/bit/Bitwise.cs b/bit/Bitwise.cs new file mode 100644 index 0000000..ed055f4 --- /dev/null +++ b/bit/Bitwise.cs @@ -0,0 +1,29 @@ + + +using System.Numerics; + +static public class bit +{ + +public static unsafe TInt ByPointers_DirectInt(TEnum enumValue) +where TInt : IBinaryInteger +where TEnum : unmanaged, System.Enum +{ +#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type + return *(TInt*)(&enumValue); +#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type + } + + + +static public bool On( T bitfield, E e ) +where T: IBinaryInteger +where E: unmanaged, System.Enum +{ + var eInt = ByPointers_DirectInt( e ); + + return (eInt & bitfield) == eInt; +} + + +}