Skip to content

Instantly share code, notes, and snippets.

@a46554
Created July 30, 2018 08: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 a46554/95f018ba5d5fc11127d8904e836be089 to your computer and use it in GitHub Desktop.
Save a46554/95f018ba5d5fc11127d8904e836be089 to your computer and use it in GitHub Desktop.
int 8_t b = -10; // b = 0xf6 for 2's complement
b = b << 1; // b=0xec
b = b >> 1; // Now b = 0x76 and for demical b = 118 unexpect ouput
// The correct way to do that operation
b = b&0x80 | b>>1;// b = 0xf6 for demical b = 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment