C programming help ....

Vu Pham vu
Fri May 19 10:41:57 PDT 2006


You can use something like

Var = 'LNDE';

And the compiler will pack it in accordingly;

int main( int c, char *args )
{
int a = (int)'XYZT';
        printf( "%02x ", (a&0xFF000000) >> 24 );
        printf( "%02x ", (a&0x00FF0000) >> 16 );
        printf( "%02x ", (a&0x0000FF00) >> 8  );
        printf( "%02x \n", (a&0xFF)  );

}
[vu at cvs vu]$ ./t
58 59 5a 54 
[vu at cvs vu]$ 


-----Original Message-----
From: linux-users-bounces at linux-sxs.org
[mailto:linux-users-bounces at linux-sxs.org] On Behalf Of Ben Duncan
Sent: Friday, May 19, 2006 10:52 AM
To: Linux tips and tricks
Subject: C programming help ....

Ok, I am trying to figure out how to "pack" hex strings a 32 bit integer.
What I need to do is code the following characters.
"LNDE", "INDE", "RNDE", "DATA", "DEAD" each into a integer.

is the correct way to do this (on a 32 bit machine) thus:

int LNDE_int = 0x4C4E4445 ;         /* Pack 'LNDE' into LNDE_int */

.. and so on and so on ....

Thanks ...




More information about the Linux-users mailing list