Skip to content

Instantly share code, notes, and snippets.

@stv0g
Created February 6, 2014 10:14
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 stv0g/8841589 to your computer and use it in GitHub Desktop.
Save stv0g/8841589 to your computer and use it in GitHub Desktop.
Sign extension
/** @brief Sign extending a integer */
size_t sign_extend(ssize_t addr, int bits)
{
return (addr << -bits) >> -bits; // sign bit is maintained during arithmetic right shift
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment