On 3/14/06, Steve Nelson <[EMAIL PROTECTED]> wrote:
> On 3/14/06, Danny Yoo <[EMAIL PROTECTED]> wrote:
>
> > The idea is to unpack four single characters as a single 4-byte integer.
>
> That's really useful, thanks, as I was planning to iterate over each
> letter and call ord()

Ok, so experimenting a little further, and looking at the
documentation, it seems that len(string) and calcsize (i) must be the
same.  Is there a reason why 'i' is a 4 byte integer?  Doesn't this
mean that this method wouldn't scale if I then decided I wanted to
use, eg, a 6 byte key instead of a four?  Or do I misunderstand?

I am also struggling to understand why a 4 byte integer is so large?

>>> mystring = "Hello I am Steve"
>>> import struct
>>> struct.unpack('i', mystring[0:4])
(1819043144,)

I can see that the largest number I can generate in a 1 byte integer
is 255 - which is (2^8)-1.  Is the point that with a 4 byte number I
can actually get (2^32)-1 , ie 4294967295?  This just seems like a
huge number!

I suppose I've answered my question... but any comments or
clarifications would help a lot.

S.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to