R
Richard Heathfield
Roman Mashak said:
Nothing. The "significant digits" that you might lose are insignificant,
since they are a side-effect of promotion with which you need not concern
yourself for the purposes of this line of code.
Let's assume 8-bit bytes, 2-byte ints (because it's less to type).
We'll assume pIRV->Val has the value 00111101, and Mask has the value
10101010.
If you thought ~Mask was 01010101, you'd be forgivably wrong. It's actually
1111111101010101 (on the system we're assuming). When you & this with
00111101 (or rather, 0000000000111101) you get 0000000000010101, and you
then store this in an unsigned char, getting 00010101, which is precisely
what you want.
If your system has bigger bytes, bigger ints, or both, then you just get
more leading 0s to ignore. No big deal.
Compiling it with borland builder results with warning on
"pIRV->Val&=~Mask" line: "conversion may loose significant digits". Both
operands are (pIRV->Val and Mask) of the same type (UCHAR, which is
'unsigned char'). What's wrong with this snippet?
Nothing. The "significant digits" that you might lose are insignificant,
since they are a side-effect of promotion with which you need not concern
yourself for the purposes of this line of code.
Let's assume 8-bit bytes, 2-byte ints (because it's less to type).
We'll assume pIRV->Val has the value 00111101, and Mask has the value
10101010.
If you thought ~Mask was 01010101, you'd be forgivably wrong. It's actually
1111111101010101 (on the system we're assuming). When you & this with
00111101 (or rather, 0000000000111101) you get 0000000000010101, and you
then store this in an unsigned char, getting 00010101, which is precisely
what you want.
If your system has bigger bytes, bigger ints, or both, then you just get
more leading 0s to ignore. No big deal.