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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -