-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitwise.go
41 lines (37 loc) · 824 Bytes
/
bitwise.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package netadv
// SliceAnd return an AND on two slice of bytes
func SliceAnd(s1, s2 []byte) []byte {
mini := MinI(len(s1), len(s2))
s := make([]byte, mini)
for i := 0; i < mini; i++ {
s[i] = s1[i] & s2[i]
}
return s
}
// SliceOr return an OR on two slice of bytes
func SliceOr(s1, s2 []byte) []byte {
mini := MinI(len(s1), len(s2))
s := make([]byte, mini)
for i := 0; i < mini; i++ {
s[i] = s1[i] | s2[i]
}
return s
}
// SliceXor return an XOR on two slice of bytes
func SliceXor(s1, s2 []byte) []byte {
mini := MinI(len(s1), len(s2))
s := make([]byte, mini)
for i := 0; i < mini; i++ {
s[i] = s1[i] ^ s2[i]
}
return s
}
// SliceNot return the NOT of bytes slice
func SliceNot(s1 []byte) []byte {
mini := len(s1)
s := make([]byte, mini)
for i := 0; i < mini; i++ {
s[i] = ^s1[i]
}
return s
}