-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (45 loc) · 1.85 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"github.com/kecci/go-bitwise-operations/bitshift"
"github.com/kecci/go-bitwise-operations/bitwise"
)
func main() {
// ===================================================================
// BITWISE
// ===================================================================
a := uint8(12) // Binary: 00001100
b := uint8(10) // Binary: 00001010
// Bitwise AND
fmt.Printf("[Bitwise] AND: %08b\n", bitwise.And(a, b))
// Bitwise OR
fmt.Printf("[Bitwise] OR: %08b\n", bitwise.Or(a, b))
// Bitwise XOR
fmt.Printf("[Bitwise] XOR: %08b\n", bitwise.Xor(a, b))
// Bitwise NOT
fmt.Printf("[Bitwise] NOT: %08b\n", bitwise.Not(a))
println("=============================================================")
// ===================================================================
// BITSHIFT
// ===================================================================
num := 1 // Binary: 1010
shift := 31 // Shift Position: 31
numBits := 31 // N-bit
fmt.Printf("[Bitshift] Original number: %d\n", num)
// Bitshift Left shift by 31 shifts
fmt.Printf("[Bitshift] LeftShift number: %d (Shifts: %d)\n", bitshift.LeftShift(num, shift), shift)
// Bitshift Right shift by 31 shifts
fmt.Printf("[Bitshift] RightShift number: %d (Shifts: %d)\n", bitshift.RightShift(num, shift), shift)
// Bitshift Left circular shift by 31 shifts and 32-bit
leftCircular, err := bitshift.LeftCircularShift(num, shift, numBits)
if err != nil {
panic(err)
}
fmt.Printf("[Bitshift] LeftCircularShift number: %08b (Shifts: %d Bits: %d)\n", leftCircular, shift, numBits)
// Bitshift Right circular shift by 31 shifts and 32-bit
rightCircular, err := bitshift.RightCircularShift(num, shift, numBits)
if err != nil {
panic(err)
}
fmt.Printf("[Bitshift] RightCircularShift number: %08b (Shifts: %d Bits: %d)\n", rightCircular, shift, numBits)
}