A method of decoding first data encoded by an LDPC code and second data encoded by a convolutional code or a turbo code is described. The method includes decoding first data by an LDPC decoder operating on a LDPC parity-check matrix. The method further includes decoding second data by the LDPC decoder operating on a sparse parity-check matrix defined by the convolutional code or the turbo code, respectively. The same decoder hardware may be used for decoding LDPC codes and convolutional codes or turbo code. In one embodiment an LDPC decoder is used for decoding a convolutional code or a turbo code. In all these cases decoding may be performed by using a message-passing algorithm. When switching from one channel code to the other channel code (e.g. from an LDPC code to a convolutional code or turbo code), the message passing algorithm is simply adapted by reprogramming the decoder to operate according to the Tanner graph representing the (sparse) parity-check matrix of the newly elected code.