Solution 2 is not quite correct.
The corrected pseudo-code is:
if (first bit (#0) in y1 is set)
{
demo = x1 + 0.5;
}
else
{
demo = x1;
}
The bit check is done by the bitwise AND operator '&': test number
y1
is compared with a bit mask with a single bit installed (1, 2, 4, 8, etc.) and the result is either 0 or not.
Now, the trick is: if the operand of "
if
" is a number, it behaves as False if the number is 0, True in all other cases; this is a dirty C-like convention.
Please see, for example,
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators[
^].
—SA