Boolean data type has two possible truth values to represent logic.
📦 GoDev,
:newspaper: GoDoc,
:blue_book: Wiki.
Here is my implementation of digital logic gates in software. That includes
the basic gates Not, And, Or, Xor; their complements Nand, Nor,
Xnor; and 2 propositional logic (taught in discrete mathematics) gates
Imply, Eq; and their complements Nimply, Neq. There is also a
multiplexer, called Select, and a true
counter, called Count. Count
can help you make custom gates, such as an alternate concept of xnor
which returns true
only if all inputs are the same (standard Xnor returns
true
if even inputs are true
). All of them can handle upto 8 inputs.
Parse is influenced by "boolean" package, and is quite good at translating
string
to boolean
. It can also handle double negatives, eg. not inactive
.
You know the And of 2-inputs, but what of 1-input? What of 0? And what of
the other gates? I answer them here.
Stability: Experimental.
import (
boolean "github.com/golangf/extra-boolean"
)
boolean.Parse("1")
boolean.Parse("truthy")
boolean.Parse("not off")
// true
boolean.Parse("not true")
boolean.Parse("inactive")
boolean.Parse("disabled")
// false
boolean.Imply(true, false)
// false
boolean.Eq(false, false)
// true
boolean.Xor3(true, true, true)
// true
boolean.Select3(1, true, false, true)
// false ^
boolean.Count3(true, false, true)
// 2 ^ ^
Name | Action |
---|---|
Parse | Converts string to boolean. |
Not | Checks if value is false. |
And | Checks if all values are true. |
Or | Checks if any value is true. |
Xor | Checks if odd no. of values are true. |
Nand | Checks if any value is false. |
Nor | Checks if all values are false. |
Xnor | Checks if even no. of values are true. |
Eq | Checks if antecedent ⇔ consequent (a ⇔ b). |
Neq | Checks if antecedent ⇎ consequent (a ⇎ b). |
Imply | Checks if antecedent ⇒ consequent (a ⇒ b). |
Nimply | Checks if antecedent ⇏ consequent (a ⇏ b). |
Select | Checks if ith value is true. |
Count | Counts no. of true values. |
- How do I do a case insensitive regular expression in Go?
- Convert string to integer type in Go?
- Set a global variable only once in golang
- GoDoc add newline character
- Indentation is replaced with tabs from spaces on save ...
- Testable Examples in Go
- Godoc: documenting Go code
- Optional Parameters in Go?
- Publishing Go Modules
- Developing and publishing modules
- Using Go Modules
- Go naming conventions for const
- What are conventions for filenames in Go?
- Go Project Structure Best Practices
- Naming Conventions in Go: Short but Descriptive
- Effective Go
- How to Write Go Code
- How to fix “go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src”
- Batch Rename