I store a byte and its complement as a simple integrity check: uint8_t a = 0x5A; uint8_t b = 0xA5;. The test if (~a == b) is never true, although ~0x5A is 0xA5 on paper. A second puzzle in the same project: with uint8_t x = 200, y = 100; the test if (x + y > 255) is true, even though I expected the sum to wrap to 44 in an 8-bit type.
What rule is being applied here, and how should I write these expressions so that they behave the same on an 8-bit AVR and a 32-bit ARM?




