Hi Kamilche,
Aside from the 7bit confusion you should take a look at the 'struct'
module. I bet it will simplify your life considerably.
#two chars
>>> import struct
>>> struct.pack('cc','A','B')
'AB'
#unsigned short + two chars
>>> struct.pack('Hcc',65535,'a','b')
'\xff\xffab'
Cheers
Lars
--
> Quite. Although you can sort of see how one might naively arrive at
this
> conclusion: one 7-bit char takes 0...127, which when you put it into
an
> 8-bit byte leaves 128...255 unused for a second char
>
> James
Yep, that's what I was doing. Guess I was too tired to program usefully
last nig
Dennis Lee Bieber wrote:
On Thu, 24 Feb 2005 14:22:59 -, "Richard Brodie" <[EMAIL PROTECTED]>
declaimed the following in comp.lang.python:
"John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Essentially, it should be possible to use a 'packed string' format in
Python, wh
"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 23 Feb 2005 22:06:54 -0800, "Kamilche" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>>
>> Essentially, it should be possible to use a 'packed string' format in
>> Python, where as long as t
"John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> >Essentially, it should be possible to use a 'packed string' format in
> >Python, where as long as the characters you're sending are in the ASCII
> >range 0 to 127, two will fit in a byte.
>
> It should be possible, but o
At programming level it seems correct (a part a "return" closure
needed for the "main" function).
But the error is IMHO conceptual:
for a char you need 7 bits (from 0 to 127 or in hex from x00 to x7F)
and you can't accomodate the other char in only one bit!
The other 128 symbols (from 128 to 255 o
On 23 Feb 2005 22:06:54 -0800, "Kamilche" <[EMAIL PROTECTED]>
wrote:
>I'm trying to pack two characters into a single byte, and the shifting
>in Python has me confused.
>
>Essentially, it should be possible to use a 'packed string' format in
>Python, where as long as the characters you're sending