Finding whether a signed and an unsigned integer are both even or both odd

Don’t use %. This is a problem that calls for bitmasks:

bool same_parity = (i & 0x1) == (j & 0x1);

This works regardless of the sign of i, since the result of that expression will always be 0 or 1.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)