Further modifications to to5BitEncoding

Ensuring conversion between uchar and ulong is correct