fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getBit8(int *pInt32, int index) {
  5. return (*pInt32 >> (index * 8)) & (0xff >> sizeof(int));
  6. }
  7.  
  8. int getBit8x(int32_t *pInt32, int index) {
  9. return (*pInt32 >> (index * 8)) & (0xff >> 32);
  10. }
  11.  
  12. int main() {
  13. int a[] = { 0, 1, 2, 3 };
  14. getBit8(a, 2);
  15. getBit8x(a, 1);
  16. printf("%d %d %d %d", a[0], a[1], a[2], a[3]);
  17. }
  18.  
  19. //http://pt.stackoverflow.com/q/190575/101
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
0 1 2 3