Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Logical-operations/Go/logical-operations-1.go
Normal file
5
Task/Logical-operations/Go/logical-operations-1.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func printLogic(a, b bool) {
|
||||
fmt.Println("a and b is", a && b)
|
||||
fmt.Println("a or b is", a || b)
|
||||
fmt.Println("not a is", !a)
|
||||
}
|
||||
35
Task/Logical-operations/Go/logical-operations-2.go
Normal file
35
Task/Logical-operations/Go/logical-operations-2.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
// stackoverflow.com/questions/28432398/difference-between-some-operators-golang
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// Use bitwise OR | to get the bits that are in 1 OR 2
|
||||
// 1 = 00000001
|
||||
// 2 = 00000010
|
||||
// 1 | 2 = 00000011 = 3
|
||||
fmt.Println(1 | 2)
|
||||
|
||||
// Use bitwise OR | to get the bits that are in 1 OR 5
|
||||
// 1 = 00000001
|
||||
// 5 = 00000101
|
||||
// 1 | 5 = 00000101 = 5
|
||||
fmt.Println(1 | 5)
|
||||
|
||||
// Use bitwise XOR ^ to get the bits that are in 3 OR 6 BUT NOT BOTH
|
||||
// 3 = 00000011
|
||||
// 6 = 00000110
|
||||
// 3 ^ 6 = 00000101 = 5
|
||||
fmt.Println(3 ^ 6)
|
||||
|
||||
// Use bitwise AND & to get the bits that are in 3 AND 6
|
||||
// 3 = 00000011
|
||||
// 6 = 00000110
|
||||
// 3 & 6 = 00000010 = 2
|
||||
fmt.Println(3 & 6)
|
||||
|
||||
// Use bit clear AND NOT &^ to get the bits that are in 3 AND NOT 6 (order matters)
|
||||
// 3 = 00000011
|
||||
// 6 = 00000110
|
||||
// 3 &^ 6 = 00000001 = 1
|
||||
fmt.Println(3 &^ 6)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue