Skip to content

Instantly share code, notes, and snippets.

@aJanuary
Created April 27, 2011 08:08
Show Gist options
  • Save aJanuary/943890 to your computer and use it in GitHub Desktop.
Save aJanuary/943890 to your computer and use it in GitHub Desktop.
A function to decode a uint into a series of boolean values.
public const int MaxStateSize = sizeof(uint) * 8;
public static IEnumerable<bool> DecodeState(uint state) {
return DecodeState(state, MaxStateSize);
}
public static IEnumerable<bool> DecodeState(uint state, int stateSize) {
if (stateSize < 0 || stateSize > MaxStateSize) {
throw new ArgumentException("stateSize");
}
for (int i = stateSize - 1; i >= 0; i -= 1) {
yield return (state & (1 << i)) > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment