github.com/tunabay/go-bitarray@v1.3.1/bitarray_format_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_Format_printf() {
    14  	ba := bitarray.MustParse("1111-0000 1010-0011 111")
    15  
    16  	fmt.Printf("%b\n", ba)      // 1111000010100011111
    17  	fmt.Printf("% b\n", ba)     // 11110000 10100011 111
    18  	fmt.Printf("%#b\n", ba)     // 1111-0000 1010-0011 111
    19  	fmt.Printf("%o\n", ba)      // 7412174
    20  	fmt.Printf("%+x\n", ba)     // f0a3e(pad=1)
    21  	fmt.Printf("%q\n", ba)      // "1111000010100011111"
    22  	fmt.Printf("[%24b]\n", ba)  // [     1111000010100011111]
    23  	fmt.Printf("[%-24b]\n", ba) // [1111000010100011111     ]
    24  
    25  	// Output:
    26  	// 1111000010100011111
    27  	// 11110000 10100011 111
    28  	// 1111-0000 1010-0011 111
    29  	// 7412174
    30  	// f0a3e(pad=1)
    31  	// "1111000010100011111"
    32  	// [     1111000010100011111]
    33  	// [1111000010100011111     ]
    34  }