github.com/tunabay/go-bitarray@v1.3.1/buffer_slice_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 ExampleBuffer_Slice() { 14 ba := bitarray.MustParse("0011-1010 0110-1111 110") 15 buf := bitarray.NewBufferFromBitArray(ba) 16 17 buf2 := buf.Slice(4, 14) 18 fmt.Println(buf2) 19 buf3 := buf.Slice(9, 13) 20 fmt.Println(buf3) 21 22 // Output: 23 // 1010011011 24 // 1101 25 } 26 27 func ExampleBuffer_SliceToEnd() { 28 ba := bitarray.MustParse("0011-1010 0110-1") 29 buf := bitarray.NewBufferFromBitArray(ba) 30 31 fmt.Println(buf.SliceToEnd(4)) 32 fmt.Println(buf.SliceToEnd(9)) 33 34 // Output: 35 // 101001101 36 // 1101 37 } 38 39 func ExampleBuffer_Slice_update() { 40 ba := bitarray.MustParse("1000-0000 0000-01") 41 buf := bitarray.NewBufferFromBitArray(ba) 42 43 sub := buf.Slice(6, 10) 44 fmt.Println(buf, sub) 45 46 sub.FillBitsAt(0, 4, 1) 47 fmt.Println(buf, sub) 48 49 buf.FillBitsAt(7, 2, 0) 50 fmt.Println(buf, sub) 51 52 // Output: 53 // 10000000000001 0000 54 // 10000011110001 1111 55 // 10000010010001 1001 56 }