bitshit in Python

Gorny gorny at hobbiton.org
Sat May 26 09:27:23 EDT 2001


Hello,

I've got the following code in C and it works perfect.. :)

----code----
#include <stdio.h>

struct structje {
unsigned char eerste:4, tweede:4;
};

struct structje blaatje;

void blaat(void) {
blaatje.eerste = 5;
blaatje.tweede = 4;
}

int main(void) {
blaat();
return 0;
}
----end-of-code----

But now I wanted to achieve the same goal in Python. I've search
through several manuals and the site but couldn't find anything
useful. Does anybody have an idea about how to put two unsigned
chars into one byte in Python???

Greetz,
Gorny


--
Never trust anything that bleeds for 3-5 days and doesn't die...
http://gorny.cjb.net


PS. This could be usefull too...
/*
Assembler debug code from blaat():

0x804847c <blaat>: push %ebp
0x804847d <blaat+1>: mov  %esp, %ebp
0x804847f <blaat+3>: andb $0xf0, 0x80495ac
0x8048486 <blaat+10>: orb $0x5, 0x80495ac
0x804848d <blaat+17>: andb $0xf, 0x80495ac
0x8048494 <blaat+24>: orb $0x40, 0x80495ac
0x804849b <blaat+31>: leave
0x804849c <blaat+32>: ret
0x804849d <blaat+33>: lea 0x0(%esi),%esi
End of assembler dump.
*/





More information about the Python-list mailing list