c++ - bitwise OR int and char -
i have value know less 16 (no more 4 bits) in int. want bitwise-or char. can this:
c |= i; or depend on endianness? if problem, this:
c |= (char)i; solve it?
endianness never matters when doing arithmetic, matters when dealing values (larger 1 char) in other way, i.e. when using char-pointers traverse buffers holding larger values, instance.
in case, there no need cast, automatic arithmetic promotion make sure it's fine. code:
char c = 0; int =3; c |= i; is equivalent to
c = c | i; the expression computed int, , converted down storage.
Comments
Post a Comment