Added Two's compliment encode - working with both positive and negative values.