fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5. short i = -6566;
  6.  
  7. //char a[2];
  8.  
  9. unsigned char a[2];
  10.  
  11. a[0]=(i>>8) & 0xff;
  12. a[1]=i & 0xff;
  13.  
  14. //short j = (a[0] << 8) | (0x00ff & a[1]);
  15. short j = (a[0] << 8) | a[1];
  16.  
  17. printf("size = %d,i = %d\n",sizeof(i),i);
  18.  
  19. printf("j = %d,%d\n",j,(unsigned short)j);
  20.  
  21. printf("a0 = %0x,a1=%0x \n",a[0],a[1]);
  22.  
  23. printf("a0 = %0x,a1=%0x \n",(unsigned char)a[0],(unsigned char)a[1]);
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
size = 2,i = -6566
j = -6566,58970
a0 = e6,a1=5a 
a0 = e6,a1=5a