G
Guest
I am trying to understand an example where the Least Significant Bit is
replaced. The code is in C# and I am having problems with a line that reads:
B= (byte) (Value == 1 ? B | (1 << poss) : B & ~ (1 << poss));
here B is the byte where we change the bit (Value) and poss = 0
I think in VB it would be something like:
if (Value = 1) then
B=B or (1 << poss)
else
B= B and [here I don't know what to do with ~] (1 << poss)
endif
I think that the condition is: if value is equal to 1 then B states the same
or it would be (1 << poss), I don't understand this since shifting 1 to 0 is
the same as 1. The else condition I don't understand at all. Could someone
please help me understand this, I would really appreciate the help.
replaced. The code is in C# and I am having problems with a line that reads:
B= (byte) (Value == 1 ? B | (1 << poss) : B & ~ (1 << poss));
here B is the byte where we change the bit (Value) and poss = 0
I think in VB it would be something like:
if (Value = 1) then
B=B or (1 << poss)
else
B= B and [here I don't know what to do with ~] (1 << poss)
endif
I think that the condition is: if value is equal to 1 then B states the same
or it would be (1 << poss), I don't understand this since shifting 1 to 0 is
the same as 1. The else condition I don't understand at all. Could someone
please help me understand this, I would really appreciate the help.