Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. unsigned char a = (unsigned char)-5;
  2. unsigned char b = (unsigned char)94;
  3.  
  4. int c = (int)((((unsigned int) a) << 8) | (unsigned int) b);
  5.  
  6. printf("%dn", c);
  7.  
  8. #include <stdio.h>
  9. #include <stdint.h>
  10.  
  11. int main() {
  12. unsigned char a = (unsigned char)-5;
  13. unsigned char b = (unsigned char)94;
  14. int16_t c = (int16_t)((((unsigned int) a) << 8) | (unsigned int) b);
  15. printf("%dn", c);
  16. }
  17.  
  18. unsigned char a = (unsigned char)-5;
  19. unsigned char b = (unsigned char)94;
  20. int c = (signed char)a << 8 | b;
  21. printf("%dn", c); // Prints -1186
  22.  
  23. signed char x = -5;
  24. signed char y = 94;
  25. int c = x * 256 + y;
  26.  
  27. int c = (int16_t)(x * 256 + y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement