[TAV-433] Fix character encoding bug for large port values.

Reading and writing affected. Tests included for both input and output port
types to check for regression in either.