Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Bitset(int data = 0) : IEquatable<Bitset>
- {
- public bool this[int i]
- {
- get
- {
- if (i < 0 or >= 32)
- throw new ArgumentOutOfRangeException();
- int mask = 1 << i;
- return (_data & mask) == mask;
- }
- set
- {
- if (i < 0 or >= 32)
- throw new ArgumentOutOfRangeException();
- int mask = 1 << i;
- value ? _data |= mask : _data &= ~mask;
- }
- }
- public bool Equals(Bitset other) => _data == other._data;
- public override bool Equals(object? o) => o is Bitset other && Equals(other);
- public override int GetHashCode() => _data.GetHashCode();
- public static operator ==(Bitset left, Bitset right) => left.Equals(right);
- public static operator !=(Bitset left, Bitset right) => !left.Equals(right);
- private int _data = data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement