from typing import Optional
import binascii


def hex_repr(b: bytes, pad: Optional[int]=None, prefix=True):
    """Get hex string representation of a byte array

    :param b: byte array
    :param pad: pad to fixed number of characters
    :param prefix: prefix with '0x'
    """
    s = binascii.hexlify(b).decode()
    if pad is not None:
        s = ("00" * min(0, pad - len(b))) + s
    if prefix:
        s = "0x" + s
    return s