Exemple #1
0
main()
{
  unsigned int n = 1;
  char *p;
  
  p = (char *)&n;
  
  if(*p == 1)
    printf("Little Endian\n");
  else if(*(p + sizeof(int) - 1) == 1)
    printf("Big Endian\n");
  else
    printf("????\n");
    
  isLittleEndian();

  int i = 0x01234567;
  char *ptr = (char *)&i;

  printf("%x\t %x\n", *ptr, *(ptr+1));

  
  show_mem_rep((char *)&i, sizeof(i));

  printf("TestByteOrder = [%d]\n", TestByteOrder());
  
}
Exemple #2
0
/*Main function to call above function for 0x01234567*/
int main()
{
   int i = 0x01234567;
   show_mem_rep((char *)&i, sizeof(i));
   getchar();
   return 0;
}
Exemple #3
0
/*Main function to call above function for 0x01234567*/
int main()
{
    // int i = 0x01234567; // 01 : 1 byte, 23 : 1 byte etc. + 0x indicates its hex
    int i = 4660; // 0x1234 (hex)
    // int i = 0x123456789123; // int overflow
    
    printf("%lu", sizeof(i)); // int is always 4
    printf("\n");
    // typecast => character pointer is pointing to an integer i
    // => Since size of character is 1 byte when the character pointer 
    // is de-referenced it will contain only first byte of integer
    show_mem_rep((char *)&i, sizeof(i));
    // getchar();
    return 0;
}