github.com/tunabay/go-bitarray@v1.3.1/bitarray_shift_example_test.go (about) 1 // Copyright (c) 2021 Hirotsuna Mizuno. All rights reserved. 2 // Use of this source code is governed by the MIT license that can be found in 3 // the LICENSE file. 4 5 package bitarray_test 6 7 import ( 8 "fmt" 9 10 "github.com/tunabay/go-bitarray" 11 ) 12 13 func ExampleBitArray_Reverse() { 14 ba := bitarray.MustParse("1100-1111 0000-1010") 15 16 fmt.Printf("% b\n", ba.Reverse()) 17 18 // Output: 19 // 01010000 11110011 20 } 21 22 func ExampleBitArray_ShiftLeft() { 23 ba := bitarray.MustParse("1100-1111 0000-1010 11") 24 25 fmt.Printf("% b\n", ba.ShiftLeft(1)) 26 fmt.Printf("% b\n", ba.ShiftLeft(8)) 27 fmt.Printf("% b\n", ba.ShiftLeft(-5)) 28 fmt.Printf("% b\n", ba.ShiftLeft(0)) 29 30 // Output: 31 // 10011110 00010101 10 32 // 00001010 11000000 00 33 // 00000110 01111000 01 34 // 11001111 00001010 11 35 } 36 37 func ExampleBitArray_RotateLeft() { 38 ba := bitarray.MustParse("1100-1111 0000-1010 11") 39 40 fmt.Printf("% b\n", ba.RotateLeft(1)) 41 fmt.Printf("% b\n", ba.RotateLeft(8)) 42 fmt.Printf("% b\n", ba.RotateLeft(-5)) 43 fmt.Printf("% b\n", ba.RotateLeft(0)) 44 45 // Output: 46 // 10011110 00010101 11 47 // 00001010 11110011 11 48 // 01011110 01111000 01 49 // 11001111 00001010 11 50 }