This program takes the command line argument and fill write_key array
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int i,j; unsigned char write_key[16]; for(j=0;j<4;j++){ for(i=0;i<4;i++){ write_key[j*4 + i] = (strtol(argv[1+j],NULL,16)>>(8*(4-1-i))) & 0xff; } } for(i=0;i<16;i++){ printf("write_key[%d] :: 0x%x \n", i, writekey[i]); } printf("\n"); } I launch the program with
./app 0xffffffff 0xffffffff 0xffffffff 0xffffffff For following input output on my linux pc is
write_key[0] :: 0xff write_key[1] :: 0xff write_key[2] :: 0xff write_key[3] :: 0xff write_key[4] :: 0xff write_key[5] :: 0xff write_key[6] :: 0xff write_key[7] :: 0xff write_key[8] :: 0xff write_key[9] :: 0xff write_key[10] :: 0xff write_key[11] :: 0xff write_key[12] :: 0xff write_key[13] :: 0xff write_key[14] :: 0xff write_key[15] :: 0xff Which is as expected. but when i cross compiled this program for Mips based embedded board and run it there my output is.
write_key[0] :: 0x7f write_key[1] :: 0xff write_key[2] :: 0xff write_key[3] :: 0xff write_key[4] :: 0x7f write_key[5] :: 0xff write_key[6] :: 0xff write_key[7] :: 0xff write_key[8] :: 0x7f write_key[9] :: 0xff write_key[10] :: 0xff write_key[11] :: 0xff write_key[12] :: 0x7f write_key[13] :: 0xff write_key[14] :: 0xff write_key[15] :: 0xff Why there is a difference in output for different architecture ?
strtol("ffffffff", NULL, 16)return on the two platforms?