Source: https://www.fil.univ-lille1.fr/~wegrzyno/portail/Codage/Doc/TD/td2.pdf