github.com/tunabay/go-bitarray@v1.3.1/bitarray_convert_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 "math/big" 10 11 "github.com/tunabay/go-bitarray" 12 ) 13 14 func ExampleNewFromInt() { 15 v := big.NewInt(1234567890123456) 16 ba := bitarray.NewFromInt(v) 17 fmt.Printf("% s\n", ba) 18 19 // Output: 20 // 10001100 01011010 10100111 10010001 01010111 01011000 000 21 } 22 23 func ExampleBitArray_ToInt() { 24 ba := bitarray.MustParse("00001001 00110010 11000000 01011010 010") 25 fmt.Println(ba.ToInt()) 26 27 // Output: 28 // 1234567890 29 } 30 31 func ExampleBitArray_ToUint64() { 32 ba := bitarray.MustParse("10010011 00101100 00000101 10111010 10") 33 fmt.Println(ba.ToUint64()) 34 35 // Output: 36 // 9876543210 37 }