lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Nov 4, 2014, at 1:25 PM, Jay Carlson <nop@nop.com> wrote:


On Nov 4, 2014 3:51 PM, "Tim Hill" <drtimhill@gmail.com> wrote:
>
>
>> On Nov 4, 2014, at 11:10 AM, Jay Carlson <nop@nop.com> wrote:
>>
>> On Nov 4, 2014 1:28 PM, "Tim Hill" <drtimhill@gmail.com> wrote:
>>
>> > Have you thought of using the new string.unpack() function to get the 3 bytes as a 64-bit integer? No idea if it would be faster, but perhaps doing multiple integer unpacks in one call would do it. Once you have the integer, peeling off 6 bits at a time is easy.
>>
>> Surely you mean "12 bits at a time"... wait, no, I'm not going to play this game…
>
> er, no .. you take 3 input bytes = 24 bits, then use this to generate 4 output bytes, so 6 input bits per byte. So of reach output byte you mask the lower 6 bits and lookup the output byte/character, then shift right 6 bits and repeat 4 times.

Or you mask off the lower 12 bits and look in your table of base64half = {

  [0] = "AA", [1] = "AB", [2] = "AC", ...
  [1*64+0] = "BA", [1*64+1] = "BB", ...
  ... [63*64+62] = "/+", [63*64+63] = "//"

The padding is a pain for everyone.

Characterizing the cache effects of this craziness is left to the reader.

Agreed :)