1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
def getBit (value, bit) :
return (value >> bit) & 1
def setBit (value, bit, bitValue) :
bitValue = (bitValue&1)<<bit
mask = (1)<<bit
return (value & ~mask) | bitValue
def initKbit (k) :
# on a besoin de k bit pour encoder les nombres du dico
# mais a la fin on ecrit quand meme des octets, donc on initialise les octets
# dans leur totalite
k = k + k%8
value = 0
for i in range (0,k) :
value = setBit (value, i, 0)
return value
def printBit (value, k) :
# On affiche le contenu complet des octets occupes
k = k + k%8
for i in range (0,k) :
print getBit (value,i)
def writeBit2Oct (value, k) :
iB = 0
iE = 8
c = initKbit (8)
while iB < iE :
c = setBit (value,iB,getBit(value,iB))
iB = iB + 1
print 'writeBit2Oct'
print 'c = '
print chr(c)
def getOctet (value,o) :
print 'getOctet'
r = initKbit (8)
for i in range (o*8,(o+1)*8) :
r = setBit (r,i%8, getBit (value,i))
print 'r = '
printBit (r,8)
print 'fin r'
return r |
Partager