Java – converts two Boolean values to int
•
Java
This can be very easy
If I have two Boolean values a and B, how can I get the equivalent "binary" number?
false and false = 0 false and true = 1 true and false = 2 true and true = 3
Solution
(left ? 2 : 0) + (right ? 1 : 0);
(left ? 2 : 0) + (right ? 1 : 0);
I'm not sure if Java handles Boolean values like C, but if so:
2*left+right;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码