def dec2hex(num, positions=2, base=16):
    """ Like chr(), but as string """
    retval = ''
    chars = '0123456789ABCDEF'
    for count in range(positions - 1, -1, -1):
        value = base ** count
        digit = chars[int(num / value)]
        retval += digit
        num -= int(num / value) * value
    return retval
