Avoid left shift of negative values (ubsan)

Change-Id: If465c155c70ec068b6bd7adc05f188bbecc2824e