How to simulate a NOR gate in JavaScript?

后端 未结 5 1303
滥情空心
滥情空心 2021-01-21 05:26

Does anyone know a way to simulate a NOR-gate in JavaScript?

https://en.wikipedia.org/wiki/NOR_gate

From what I have seen so far the language has only AND and OR

相关标签:
5条回答
  • 2021-01-21 06:01

    Here's the bitwise version:

    ~(a | b)
    
    0 讨论(0)
  • 2021-01-21 06:04

    Always you could negate the logic or making something like this:

    if(!(true || true))
    

    this way you always going to obtain the or result negated, which really have a NOR-gate behavior.

    0 讨论(0)
  • 2021-01-21 06:06

    well the easiest way : !(a || b)

    0 讨论(0)
  • 2021-01-21 06:15

    This is a NOT-AND gate which is equal to an AND gate followed by a NOT gate.

    if(!(a && b)) { // code }
    
    0 讨论(0)
  • 2021-01-21 06:20

    You can use a reversed && like so:

    var a = false;
    var b = false;
    
    if ( !a && !b ) {
        // some code
    }
    
    0 讨论(0)
提交回复
热议问题