xor: how come so slow?
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Sun Oct 19 19:42:06 EDT 2008
In message <gdea3t$4tj$1 at lust.ihug.co.nz>, Lawrence D'Oliveiro wrote:
> In message <010a9c3f$0$20653$c3e8da3 at news.astraweb.com>, Steven D'Aprano
> wrote:
>
>> On Sat, 18 Oct 2008 09:16:11 +1300, Lawrence D'Oliveiro wrote:
>>
>>> Data can come in fractional bits. That's how compression works.
>>
>> If you don't believe me, try compressing a single bit and see if you get
>> a "fractional bit".
>
> If both states of the bit are not equally likely, then you do indeed have
> a fractional bit, since
>
> nrbits = (- logbase2(P[bit = 0]) - logbase2(P[bit = 1])) / 2
Oops, sorry, the formula should of course be
nrbits = - P[bit = 0] * logbase2(P[bit = 0])
- P[bit = 1] * logbase2(P[bit = 1])
More information about the Python-list
mailing list