By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 428,600 Members | 1,214 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,600 IT Pros & Developers. It's quick & easy.

# casting to char*,

 P: n/a On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p = X; ? p = R; ? p = G; ? p = B; ? or p = B; ? p = G; ? p = R; ? p = X; ? Sep 15 '06 #1
Share this Question
8 Replies

 P: n/a Since you are on a little-endian machine, I believe the answer is #2. On Fri, 15 Sep 2006, vsgdp wrote: On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p = X; ? p = R; ? p = G; ? p = B; ? or p = B; ? p = G; ? p = R; ? p = X; ? Sep 15 '06 #2

 P: n/a vsgdp posted: On Windows XP, unsigned integers are 32 bits. Depends on your compiler. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p = X; ? p = R; ? p = G; ? p = B; ? or p = B; ? p = G; ? p = R; ? p = X; ? Depends how much crack you smoke, because your code has no basis in C++. -- Frederick Gotham Sep 16 '06 #3

 P: n/a On Windows XP, unsigned integers are 32 bits. Partition the bits of the unsigned integer C into 4 8-bit chunks like so: C = XRGB. Then unsigned char* p = &C; Does p = X; p = R; p = G; p = B; ? or p = B; p = G; p = R; p = X; ? Easy enough to check: unsigned int C = 1; cout << sizeof(C) << endl; unsigned char* p = (unsigned char*)&C; cout << "" << (int)p << "\t"; cout << "" << (int)p << "\t"; cout << "" << (int)p << "\t"; cout << "" << (int)p << endl; For option 1, the expected output would be 4 0 0 0 1 For option 2: 4 1 0 0 0 (Further testing with C = 256, C = 256 * 256, and C = 256*256*256 would add to the confidence you get running this.) Michael P.S. On my machine, with my compiler, I get option 2. Sep 16 '06 #4

 P: n/a On Sat, 16 Sep 2006 00:19:27 GMT, Frederick Gotham

 P: n/a Frederick Gotham

 P: n/a Jens Theisen wrote: Frederick Gotham vsgdp posted: >>On Windows XP, unsigned integers are 32 bits. Depends on your compiler. Uh? On SysV ABI compliant system such as Linux it doesn't. Are you sure that in the Windows world, there is no such standard? There is not. MS publishes an API for system calls, but have no requirements for apps (or compilers). Bo Persson Sep 16 '06 #7

 P: n/a "Bo Persson"

 P: n/a "vsgdp" >= 8; G = C & 0xff; C >>=8; R = C & 0xff; C >>= 8; X = C & 0xff; and you will not have to worry about how your particular platform behaves. Before you claim that this code will be slower than yours, please measure it. Your version requires 4 memory references (5 if C is not already in memory); mine requires none. Sep 18 '06 #9

### This discussion thread is closed

Replies have been disabled for this discussion. 