S
Simon
Hi,
I am reading a file that contains a bunch of unsigned longs.
The number itself is broken down in bits, for example
bit 31-24 is a certain code and bit 7-6 represents a certain state.
am I right in doing the following
// read the unsigned long from the file
unsigned long ulDataFromFile = 0;
/*
... read it
*/
// define some values, code and state
unsigned short usCode = 0; // size = 7 'cause we are reading bit 31-24
unsigned char ucState = 0; // size = 1 'cause we are reading bit 7-6
// use the unsigned long to read the data itself.
memcpy( &usCode, ((unsigned char*)ulDataFromFile)+24, sizeof(unsigned
char) ); // read bit 31-24
memcpy( &ucState , ((unsigned char*)ulDataFromFile)+7, sizeof(unsigned
short ) ); // read bit 7-6
Am I right?
I cannot really test the data as I am not sure what values to expect inside
the unsigned long
Many thanks in advance.
Simon
I am reading a file that contains a bunch of unsigned longs.
The number itself is broken down in bits, for example
bit 31-24 is a certain code and bit 7-6 represents a certain state.
am I right in doing the following
// read the unsigned long from the file
unsigned long ulDataFromFile = 0;
/*
... read it
*/
// define some values, code and state
unsigned short usCode = 0; // size = 7 'cause we are reading bit 31-24
unsigned char ucState = 0; // size = 1 'cause we are reading bit 7-6
// use the unsigned long to read the data itself.
memcpy( &usCode, ((unsigned char*)ulDataFromFile)+24, sizeof(unsigned
char) ); // read bit 31-24
memcpy( &ucState , ((unsigned char*)ulDataFromFile)+7, sizeof(unsigned
short ) ); // read bit 7-6
Am I right?
I cannot really test the data as I am not sure what values to expect inside
the unsigned long
Many thanks in advance.
Simon