Utility method for calculating code length