fork(1) download
  1. #include <stdio.h>
  2.  
  3. void printShort(short x) {
  4. int i;
  5. for(i = 8 * sizeof(short) - 1; i >= 0; i--) {
  6. printf("%c", (x & (1 << i)) ? '1' : '0');
  7. if(i % 4 == 0) printf(" ");
  8. }
  9. printf("\n");
  10. }
  11.  
  12. void printLong(long x) {
  13. int i;
  14. for(i = 8 * sizeof(long) - 1; i >= 0; i--) {
  15. printf("%c", (x & (1 << i)) ? '1' : '0');
  16. if(i % 4 == 0) printf(" ");
  17. }
  18. printf("\n");
  19. }
  20.  
  21. int main(void) {
  22.  
  23. printf("unsigned short a, unsigned long b\n");
  24. unsigned short a = 077;
  25. printf("a = ");
  26. printShort(a);
  27. a = ~a;
  28. printf("~a = ");
  29. printShort(a);
  30. unsigned long b = a;
  31. printf("b = ");
  32. printLong(b);
  33. printf("\n");
  34.  
  35. printf("unsigned short c, long d\n");
  36. unsigned short c = 077;
  37. printf("c = ");
  38. printShort(c);
  39. c = ~c;
  40. printf("~c = ");
  41. printShort(c);
  42. long d = c;
  43. printf("d = ");
  44. printLong(d);
  45. printf("\n");
  46.  
  47. printf("short e, unsigned long f\n");
  48. short e = 077;
  49. printf("e = ");
  50. printShort(e);
  51. e = ~e;
  52. printf("~e = ");
  53. printShort(e);
  54. unsigned long f = e;
  55. printf("f = ");
  56. printLong(f);
  57. printf("\n");
  58.  
  59. printf("short g, long h\n");
  60. short g = 077;
  61. printf("g = ");
  62. printShort(g);
  63. g = ~g;
  64. printf("~g = ");
  65. printShort(g);
  66. long h = g;
  67. printf("h = ");
  68. printLong(h);
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 2248KB
stdin
Standard input is empty
stdout
unsigned short a, unsigned long b
a = 0000 0000 0011 1111 
~a = 1111 1111 1100 0000 
b = 0000 0000 0000 0000 1111 1111 1100 0000 

unsigned short c, long d
c = 0000 0000 0011 1111 
~c = 1111 1111 1100 0000 
d = 0000 0000 0000 0000 1111 1111 1100 0000 

short e, unsigned long f
e = 0000 0000 0011 1111 
~e = 1111 1111 1100 0000 
f = 1111 1111 1111 1111 1111 1111 1100 0000 

short g, long h
g = 0000 0000 0011 1111 
~g = 1111 1111 1100 0000 
h = 1111 1111 1111 1111 1111 1111 1100 0000