code: def format_hex(i, num_bytes=4, prefix='0x'):
      
      prefix = str(prefix or '')
      i = int(i or 0)
      return prefix + '{0:0{1}x}'.format(i, num_bytes)
docs: Format hexidecimal string from decimal integer value
  
      >>> format_hex(42, num_bytes=8, prefix=None)
      '0000002a'
      >>> format_hex(23)
      '0x0017'