CRC

Hello all,
I am reading a file into a struct which is defined as
struct pack
{
unsigned long Magic;
unsigned short CRC;
int checkCRC;


} *packIt;

When i print the values of packIt->Magic and packIt->CRC, they are given as
0x31415926 and 0x8c18.
But when i do, char *buffer = (char *)packIt and
for(int i = 0; i <sizeof(buffer); i++)
printf("%x ", buffer_);
the result i get is
26
59
41
31
18
ffffff8c

I am not able to understand why i am getting ffffff8c instead of just 8c.
Can anybody explain to me why this is happening?? I have to compute CRC on
this file and because of this I am getting a wrong checksum.
Thanks,
Tray._

Looks like sign extension. In gcc chars are signed by default.
Try declaring buffer as an unsigned char *

Tray Karra <tkarra@ces.clemson.edu> wrote:

Hello all,
I am reading a file into a struct which is defined as
struct pack
{
unsigned long Magic;
unsigned short CRC;
int checkCRC;


} *packIt;

When i print the values of packIt->Magic and packIt->CRC, they are given as
0x31415926 and 0x8c18.
But when i do, char *buffer = (char *)packIt and
for(int i = 0; i <sizeof(buffer); i++)
printf("%x ", buffer> );
the result i get is
26
59
41
31
18
ffffff8c

I am not able to understand why i am getting ffffff8c instead of just 8c.
Can anybody explain to me why this is happening?? I have to compute CRC on
this file and because of this I am getting a wrong checksum.
Thanks,
Tray.


cburgess@qnx.com

Thanks colin, that infact is the probs.
“Colin Burgess” <cburgess@qnx.com> wrote in message
news:anajcd$shl$1@nntp.qnx.com

Looks like sign extension. In gcc chars are signed by default.
Try declaring buffer as an unsigned char *

Tray Karra <> tkarra@ces.clemson.edu> > wrote:
Hello all,
I am reading a file into a struct which is defined as
struct pack
{
unsigned long Magic;
unsigned short CRC;
int checkCRC;


} *packIt;

When i print the values of packIt->Magic and packIt->CRC, they are given
as
0x31415926 and 0x8c18.
But when i do, char *buffer = (char *)packIt and
for(int i = 0; i <sizeof(buffer); i++)
printf("%x ", buffer> _);
the result i get is
26
59
41
31
18
ffffff8c

I am not able to understand why i am getting ffffff8c instead of just
8c.
Can anybody explain to me why this is happening?? I have to compute CRC
on
this file and because of this I am getting a wrong checksum.
Thanks,
Tray.









\

cburgess@qnx.com_