first fix is a type cast for which the sign was not correct second fix is addition of a bit mask to deal with a reserved bit which now suddenly seems to be 1 (which was assumed to be 0)