I'm running a quick test to make sure I have my pointer arithmetic down:
main.c
#include <stdio.h>
#include <stdlib.h>
#define ADDRESS 0xC0DCA11501LL
#define LENGTH 5
void print_address( char *, char );
/* Main program */
int main( int argc, char *argv[] )
{
char nums[ LENGTH ];
/* LSB first */
for( int i = 0; i < LENGTH; i++ )
{
nums[ i ] = ( ADDRESS >> ( 8 * i ) ) & 0xFF;
}
print_address( nums, LENGTH );
system("PAUSE");
return 0;
}
void print_address( char *data, char len )
{
char *data_ptr = data;
while( len-- )
{
printf( "%X\n", *data_ptr++ );
}
}
What I expect is the bytes of ADDRESS
to be printed out LSB first in hex format. But the last 3 bytes appear to be printed with 32-bit lengths:
1
15
FFFFFFA1
FFFFFFDC
FFFFFFC0
Press any key to continue . . .
Is this due to my bit-shifting arithmetic, something compiler-specific, some printf()
behavior?
(I'm using MinGW GCC v6.3.0 on Windows 10 to compile.)