Fixed BtoI and ItoB, fixed memory decode/encode