Say I have an unsigned int x = 0x4F726E67, and I want to print the character values of that int( 0x4F, 0x72, 0x6E, 0x67 ) becomes ( 'O', 'r', 'n', 'g' ) either to stdout or to a file. There must be an easy way of doing this but it has eluded me. Any hints would be appreciated.
Example of an attempt using strtol:
Code:for( i=0; i<length/4; i++ ) { fread( &c, 4, 1, in ); c = c ^ 0x54694772; printf("c = %d = 0x%x\n", c, c ); unsigned int foo = strtol( c, NULL, 2 ); fwrite( &foo, 1, 1, out ); } fclose( in ); // Closes input file fclose( out ); // Closes output file return 0; }



LinkBack URL
About LinkBacks


