Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Bitwise-operations/Go/bitwise-operations.go
Normal file
38
Task/Bitwise-operations/Go/bitwise-operations.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func bitwise(a, b int16) {
|
||||
fmt.Printf("a: %016b\n", uint16(a))
|
||||
fmt.Printf("b: %016b\n", uint16(b))
|
||||
|
||||
// Bitwise logical operations
|
||||
fmt.Printf("and: %016b\n", uint16(a&b))
|
||||
fmt.Printf("or: %016b\n", uint16(a|b))
|
||||
fmt.Printf("xor: %016b\n", uint16(a^b))
|
||||
fmt.Printf("not: %016b\n", uint16(^a))
|
||||
|
||||
if b < 0 {
|
||||
fmt.Println("Right operand is negative, but all shifts require an unsigned right operand (shift distance).")
|
||||
return
|
||||
}
|
||||
ua := uint16(a)
|
||||
ub := uint32(b)
|
||||
|
||||
// Logical shifts (unsigned left operand)
|
||||
fmt.Printf("shl: %016b\n", uint16(ua<<ub))
|
||||
fmt.Printf("shr: %016b\n", uint16(ua>>ub))
|
||||
|
||||
// Arithmetic shifts (signed left operand)
|
||||
fmt.Printf("las: %016b\n", uint16(a<<ub))
|
||||
fmt.Printf("ras: %016b\n", uint16(a>>ub))
|
||||
|
||||
// Rotations
|
||||
fmt.Printf("rol: %016b\n", uint16(a<<ub|int16(uint16(a)>>(16-ub))))
|
||||
fmt.Printf("ror: %016b\n", uint16(int16(uint16(a)>>ub)|a<<(16-ub)))
|
||||
}
|
||||
|
||||
func main() {
|
||||
var a, b int16 = -460, 6
|
||||
bitwise(a, b)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue