Quiz Entry - updated: 2026.07.07
What happens when you cast between signed and unsigned integers in C?
Nothing in memory changes — the same bits are just reinterpreted, so a negative signed value becomes a large positive unsigned value (x + 2^w).
* The same bits, two readings: once the sign bit is 1 the unsigned reading keeps climbing while the signed reading drops by 2^w — the "ordering inversion" a cast exposes. *
int x = -1; // 0xFFFFFFFF as signed = -1
unsigned ux = x; // 0xFFFFFFFF as unsigned = 4,294,967,295
Mapping:
- Non-negative signed → same unsigned value
- Negative signed → large positive unsigned (add 2^w)
Formula: If signed value x < 0, unsigned value = x + 2^w
Warning: Comparing signed with unsigned implicitly casts signed to unsigned:
// TRUE! (-1 becomes UINT_MAX)
-1 > 0U
Go deeper:
Integer (computer science) (Wikipedia) — signed vs unsigned integer types, their ranges, and conversions.