# 65.43 Decode

`Decode( C, c )`

`Decode` decodes c with respect to code C. c is a codeword or a list of codewords. First, possible errors in c are corrected, then the codeword is decoded to an information codeword x. If the code record has a field `specialDecoder`, this special algorithm is used to decode the vector. Hamming codes and BCH codes have such a special algorithm. Otherwise, syndrome decoding is used. Encoding is done by multiplying the information vector with the code (see Operations for Codes).

A special decoder can be created by defining a function

` C.specialDecoder := function(C, c) ... end;`

The function uses the arguments C, the code record itself, and c, a vector of the codeword type, to decode c to an information word. A normal decoder would take a codeword c of the same word length and field as C, and would return a information word of length k, the dimension of C. The user is not restricted to these normal demands though, and can for instance define a decoder for non-linear codes.

```    gap> C := HammingCode(3);
a linear [7,4,3]1 Hamming (3,2) code over GF(2)
gap> c := "1010"*C;                    # encoding
[ 1 0 1 0 1 0 1 ]
gap> Decode(C, c);                     # decoding
[ 1 0 1 0 ]
gap> Decode(C, Codeword("0010101"));
[ 1 0 1 0 ]                            # one error corrected
gap> C.specialDecoder := function(C, c)
> return NullWord(Dimension(C));
> end;
function ( C, c ) ... end
gap> Decode(C, c);
[ 0 0 0 0 ]           # new decoder always returns null word ```

GAP 3.4.4
April 1997