Refactor format padded hex (16 digits) functions

The new Ghosts package also needs padded hex functions, so move most
of the history functions up one level to allow Ghosts to re-use them.