import re


def to_hex_ascii(value):
    """ Convert binary value to hex representation in ascii """
    output = ''

    # Format value to hex in ascii
    value_str = '{:02X}'.format(value)

    # Append zero if needed
    if len(value_str) % 2:
        value_str = '0' + value_str

    # Merge into 16 bit values
    value_list = re.findall('..', value_str)

    # Add '0x' prefix
    value_list = ['0x' + v for v in value_list]

    # Add newline to every 8th byte
    value_list = ['\n' + v if i != 0 and i % 8 == 0 else v for i, v in enumerate(value_list)]

    # Merge with comas
    output += ', '.join(value_list)

    output += ',\n'

    return output, len(value_list)