I'm reading a data file and four of the fields are supposed to be a 32-bit, little-endian, unsigned, integer identifying the number of records in this data file.
If I look at the file in my hex editor, I can see that the "Unsigned 32-bit" value of the first of these 4 bytes is 64745. That is the number of records in the file, so I know I'm looking in the right place.
As you'll see in my code below, I am trying to print the value. This isn't strictly necessary, but I do need to use it in a for loop later in the program.
Basically, I'm reading the file like this...
So, I'm not really getting anything useful from my [tt]printf[/tt]s, but I realize that may be a limitation of [tt]printf[/tt].
The math is my weakest area. I don't understand what "little-endian" is and my understanding of hexadecimal is pretty limited, too. I know that the right-most digit is multiplied by 1, the next one by 16, etc... I've read K&R and a few other books, but there are some parts I just don't understand.
How do I use the value effectively?
Thank you
--
-- GhodMode
If I look at the file in my hex editor, I can see that the "Unsigned 32-bit" value of the first of these 4 bytes is 64745. That is the number of records in the file, so I know I'm looking in the right place.
As you'll see in my code below, I am trying to print the value. This isn't strictly necessary, but I do need to use it in a for loop later in the program.
Basically, I'm reading the file like this...
Code:
long c;
while ( (c = getchar()) != EOF ) {
/* Read the header */
for ( i = 0; i < 32; i++ ) {
/* ... */
if ( (i >= 4) && (i <= 7) ) {
printf( "Record count(%d): %i\n", i, c );
printf( "Record count(%d): %d\n", i, c );
printf( "Record count(%d): %g\n", i, c );
printf( "Record count(%d): %f\n", i, c );
printf( "Record count(%d): %x\n", i, c );
}
/* ... */
}
/* do stuff with the data */
}
/* ... */
So, I'm not really getting anything useful from my [tt]printf[/tt]s, but I realize that may be a limitation of [tt]printf[/tt].
The math is my weakest area. I don't understand what "little-endian" is and my understanding of hexadecimal is pretty limited, too. I know that the right-most digit is multiplied by 1, the next one by 16, etc... I've read K&R and a few other books, but there are some parts I just don't understand.
How do I use the value effectively?
Thank you
--
-- GhodMode