[Previous comment advancing to reply]
It seems like this is a bitmap that is important to you, and not an integer value as such. You can save it as a signed one - just drop it, because C signed ↔ unsigned casts does not apply mathematical correctness and just saves bits. Bring it back to use it.
Next question:
In the general case, yes (Obj-) C (++) you can save an unsigned integer into a variable with an equivalent type with a signed integer type and vice versa. C differs from signed → unsigned by definition, equates to a bit copy when using 2 integers and two types are the same size. In other words, unsigned -> signed, is an "implementation defined", which in practice usually means a bit copy. Clang and GCC use a bit copy for both, but if you want to be absolutely sure, you can use union :
unsigned long r; long l; r = (unsigned long)l;
But seriously, I doubt anyone will be! (Note: Clang will at least compile it to its direct destination (bit copy).)
CRD
source share