Question
How do I use the &
binary operator correctly? randomSize is ushort.
if (randomSize & 0x1000)
{
}
Error 5 Cannot implicitly convert type 'int' to 'bool'
Thanks.
Solution
The if
statement expects a bool
value, not just some non-zero value like in C/C++. If you are checking flags, try something like this:
if ((randomSize & 0x1000) == 0x1000)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow