Improve performance of work generation by optimizing hex2bin and bin2hex

sprintf is a very expensive function, do direct translation instead.