Message143850
Yes I can. This seems strange, but it is correct. The little endian case look like:
Little endian
---------------------------------------
| unsigned short | unsigned short |
---------------------------------------
| bbbbaaaa ....cccc dddddddd ....dddd |
---------------------------------------
| 00010010 00110100 01010110 01111000 |
---------------------------------------
where the 'd' bits pack from left to right, so '1000 01010110'.
The big endian case look like:
Big endian
---------------------------------------
| unsigned short | unsigned short |
---------------------------------------
| aaaabbbb cccc.... dddddddd dddd.... |
---------------------------------------
| 00010010 00110100 01010110 01111000 |
---------------------------------------
where the 'd' bits pack from right to left, so '01010110 0111'.
The native case (Structure) can typically be verified using your host C compiler. For example, the above code can be represented in C as:
#include <stdio.h>
struct T
{
unsigned char a : 4;
unsigned char b : 4;
unsigned short c : 4;
unsigned short d : 12;
};
int main (int argc, char **argv)
{
unsigned char bytes[] = {0x12, 0x34, 0x56, 0x78};
struct T *t = (struct T*)&bytes;
printf ("%X\n", t->a);
printf ("%X\n", t->b);
printf ("%X\n", t->c);
printf ("%X\n", t->d);
}
With respect to structure layout, ctypes typically behaves the same way as the native compiler used to build the interpreter. |
|
Date |
User |
Action |
Args |
2011-09-11 02:59:22 | meador.inge | set | recipients:
+ meador.inge, Pavel.Boldin |
2011-09-11 02:59:22 | meador.inge | set | messageid: <1315709962.11.0.107021310865.issue12945@psf.upfronthosting.co.za> |
2011-09-11 02:59:21 | meador.inge | link | issue12945 messages |
2011-09-11 02:59:21 | meador.inge | create | |
|