LOGBOOK

HELP

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).

Same 4-bit patterns read as unsigned vs two's complement; the top half inverts from big-positive to negative

* 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:

From Quiz: REVE1 / Number Representations | Updated: Jul 07, 2026