General purpose binary encoder/decoder