Hi Le Anh,
how can it determinate, that the i16 value %x positive is (65535)?
And the second example:
I guess you should read up on the "two's complement" format, which is how a
signed value is stored in most architectures (and in these examples).
In short, a sext operation takes the highest bit of the original number (the
sign bit) and copies it into all the higher positions. This makes sure that
the number and the sign do not change, due to the way two's complement works.
In general, the sext operation can enlarge a signed value, while preserving
both sign and magnitude, even when the target you are compiling for has some
other way of storing signed numbers.