Fix SIGSEGV when encoding 1- or 2-byte data

Fix bug introduced by 4062db26 (arm64 support), which switched from signed to unsigned counters. It broke the for loop for small inputLength, since the comparison we did (0 < 1lu - 2lu) required signed integers.