Code for calculating entropy