Skip to content

Instantly share code, notes, and snippets.

@jcdickinson
Created August 18, 2011 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcdickinson/1154295 to your computer and use it in GitHub Desktop.
Save jcdickinson/1154295 to your computer and use it in GitHub Desktop.
static uint GetValue(uint value, int bitsToGrab, int bitsToMoveOver)
{
const uint FullMask = 0xFFFFFFFF;
value = (uint)IPAddress.HostToNetworkOrder((int)value);
var mask = FullMask << (bitsToGrab + bitsToMoveOver);
value = (value << bitsToMoveOver);
value = value & mask;
value = value >> bitsToGrab;
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment