add correct spec and behaviour for to_hex function (fix #4).