Generic function for computing encoding