Created
April 27, 2011 08:08
-
-
Save aJanuary/943890 to your computer and use it in GitHub Desktop.
A function to decode a uint into a series of boolean values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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