c - Turn on MSB of 8 bit integers -
how show mask , turn on msb of 8 bit integer? have tried different logical opeartors not getting right answers
if have 8 bit integer turning msb set '1' bit 7.
so mask 0x80 (only bit 7 on).
in order set bit can use bit-wise or |
:
#define msb_mask 0x80 // or #define msb_mask (1 << 7) int x; x = x | msb_mask; // or x |= msb_mask; make shorter
Comments
Post a Comment