1. A method for data storage, comprising: defining an end-to-end mapping between data bits to be stored in a memory device that comprises multiple memory cells and predefined programming levels; mapping the data bits into mapped bits, so that a number of the mapped bits is smaller than a number of the data bits; storing the data bits in the memory device by programming the mapped bits in the memory cells using a programming scheme that guarantees the end-to-end mapping; and after storing the data bits, reading the data bits from the memory device in accordance with the end-to-end mapping.