Created
February 6, 2014 10:14
-
-
Save stv0g/8841589 to your computer and use it in GitHub Desktop.
Sign extension
This file contains 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
/** @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