Skip to content

Instantly share code, notes, and snippets.

@Flayed
Created April 12, 2018 19:59
Show Gist options
  • Save Flayed/0b0a7e3cdb95814ed2bf6c3bf48e9e1b to your computer and use it in GitHub Desktop.
Save Flayed/0b0a7e3cdb95814ed2bf6c3bf48e9e1b to your computer and use it in GitHub Desktop.
Packing Bytes
public enum DayOfWeek
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}
private byte PackedDays { get; set; }
public DayOfWeek StartDay
{
get { return (DayOfWeek)(PackedDays & 15); }
set { PackedDays |= (byte)value; }
}
[BsonIgnore]
public DayOfWeek EndDay
{
get { return (DayOfWeek)(PackedDays >> 4); }
set { PackedDays |= (byte)((byte)value << 4); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment