Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created January 20, 2020 02:45
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 vinniefalco/d0dd4b2f9b5856de3cfcb564c6b64095 to your computer and use it in GitHub Desktop.
Save vinniefalco/d0dd4b2f9b5856de3cfcb564c6b64095 to your computer and use it in GitHub Desktop.
// return `true` if the hex
// word could be 0..255 if
// interpreted as decimal
bool
maybe_octet(long word)
{
if(word > 0x255)
return false;
unsigned short d1 =
(word >> 8) & 0xf;
if(d1 > 2)
return false;
unsigned short d2 =
(word >> 4) & 0xf;;
if(d2 > 9)
return false;
unsigned short d3 =
word & 0xf;
if(d3 > 9)
return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment