In logical calculation, how to encounter true retention and false inversion?

for example, if there are two Boolean variables amenb, respectively, when b=true returns acentrology false, it returns! a, how to implement it with simple operation?
how should I write a xxx b / / xxx?

is actually a question of how to:
true
true
fake

Note: ternary expressions will not be considered for the time being, thank you.

Feb.27,2021

like this?

var bool = true;//or false
bool ? a : !a

yours is more like XOR

console.log(!(true ^ true))//true
console.log(!(false ^ true))//false
console.log(!(false ^ false))//true

< del > a? A:! a < / del >
< del > a & & a |! a < / del >
next time, make it clear. The following is the answer to the revised question.
b & & a | |! B & &! a | | a


Ternary expression java is the same as javascript

the simplest


keep who? Against whom? a ? If a is a Boolean variable, isn't that equivalent to returning true directly? a is true keep true , a is false take a , isn't that still true ?

this is meaningless, so I assume that the subject wants to use a to control another Boolean variable b .

Let the operation result be Q , and list the truth table:

< table > < thead > < tr > < th > a < / th > < th > b < / th > < th > Q < / th > < / tr > < / thead > < tbody > < tr > < td > true < / td > < td > true < / td > < td > true < / td > < / tr > < tr > < td > true < / td > < td > false < / td > < td > false < / td > < / tr > < tr > < td > false < / td > < td > true < / td > < td > false < / td > < / tr > < tr > < td > false < / td > < td > false < / td > < td > true < / td > < / tr > < / tbody > < / table >

you can get Q =! (a ^ b) , finish. Where ^ is an XOR operation.

if b is of another type, for scripting languages, you can use Q = a? B:! B , for strongly typed languages, you need to specify a "reverse" value for b , such as NULL or something else, and then Q = a? B: NULL , of course, you can also overload the ! operator for b .

Menu