forked from tunabay/go-bitarray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitarray_shift_example_test.go
50 lines (38 loc) · 1.09 KB
/
bitarray_shift_example_test.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
// Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package bitarray_test
import (
"fmt"
"github.com/tunabay/go-bitarray"
)
func ExampleBitArray_Reverse() {
ba := bitarray.MustParse("1100-1111 0000-1010")
fmt.Printf("% b\n", ba.Reverse())
// Output:
// 01010000 11110011
}
func ExampleBitArray_ShiftLeft() {
ba := bitarray.MustParse("1100-1111 0000-1010 11")
fmt.Printf("% b\n", ba.ShiftLeft(1))
fmt.Printf("% b\n", ba.ShiftLeft(8))
fmt.Printf("% b\n", ba.ShiftLeft(-5))
fmt.Printf("% b\n", ba.ShiftLeft(0))
// Output:
// 10011110 00010101 10
// 00001010 11000000 00
// 00000110 01111000 01
// 11001111 00001010 11
}
func ExampleBitArray_RotateLeft() {
ba := bitarray.MustParse("1100-1111 0000-1010 11")
fmt.Printf("% b\n", ba.RotateLeft(1))
fmt.Printf("% b\n", ba.RotateLeft(8))
fmt.Printf("% b\n", ba.RotateLeft(-5))
fmt.Printf("% b\n", ba.RotateLeft(0))
// Output:
// 10011110 00010101 11
// 00001010 11110011 11
// 01011110 01111000 01
// 11001111 00001010 11
}