Use a bitcheck instead of casting.

The result of a cast from unsigned to signed isn't defined by the specs.

Fixes CID #965944.