in reply to question of pack.

Sorry for reply so late! I have spend two days in studying the artical as planetscape mentioned.:) According to that artical,pack is the funcation used for transfering data between machines.Number-convert is its side effect.We should use hex,oct,or sprintf to convert.
print (unpack('B8',pack('H2','ff'))) #11111111 print (unpack('B8',pack('i','120'))) #01111000 print (unpack('H2',pack('i','15'))) #0f print (unpack('H',pack('i','15'))) #0
As above,we can't get the answer you want unless we set correct digits.