Functions to encode and decode gene