fix issues with PowerPC / big-endian

This fixes two issues:
1) a call to write assumed little-endian, a cast to char is necessary to ensure the addressof operator points to the correct byte
2) a cast from int to char assumes char is signed, this cast needs to be delayed until after the sign test