Skip to content

Instantly share code, notes, and snippets.

@tmathmeyer
Last active August 29, 2015 13:57
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 tmathmeyer/9823500 to your computer and use it in GitHub Desktop.
Save tmathmeyer/9823500 to your computer and use it in GitHub Desktop.
convert byte to short in an interesting way
unsigned short byte2short(char b)
{
char c = 8;
unsigned short answer = 0;
while(c-->0){
answer<<=2;
if (b&(((char)1)<<c))
answer+=3;
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment