Design and Optimization of Adaptable BCH Codecs for NAND Flash Memories