<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _encode_char(char, charmap, defaultchar):
 """ Encode a single character with the given encoding map :param char: char to encode :param charmap: dictionary for mapping characters in this code page """

        if ord(char) < 128:
            return ord(char)
        if char in charmap:
            return charmap[char]
        return ord(defaultchar)