fork download
  1. #include <stdio.h>
  2.  
  3. int getByte(int x, int n);
  4.  
  5. int main()
  6. {
  7. int x = 0xAABBCCDD;
  8. int n;
  9.  
  10. for (n=0; n<=3; n++) {
  11. printf("byte %d of 0x%08X is 0x%08X\n", n, x, getByte(x,n));
  12. }
  13. return 0;
  14. }
  15.  
  16. // extract byte n from word x
  17. // bytes numbered from 0 (LSByte) to 3 (MSByte)
  18. int getByte(int x, int n)
  19. {
  20. return (x >> (n << 3)) & 0xFF;
  21. }
  22.  
Success #stdin #stdout 0s 4552KB
stdin
Standard input is empty
stdout
byte 0 of 0xAABBCCDD is 0x000000DD
byte 1 of 0xAABBCCDD is 0x000000CC
byte 2 of 0xAABBCCDD is 0x000000BB
byte 3 of 0xAABBCCDD is 0x000000AA