github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/src/math/bits/example_test.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bits_test
     6  
     7  import (
     8  	"fmt"
     9  	"math/bits"
    10  )
    11  
    12  func ExampleLeadingZeros16() {
    13  	fmt.Println(bits.LeadingZeros16(0))
    14  	fmt.Println(bits.LeadingZeros16(1))
    15  	fmt.Println(bits.LeadingZeros16(256))
    16  	fmt.Println(bits.LeadingZeros16(65535))
    17  	// Output:
    18  	// 16
    19  	// 15
    20  	// 7
    21  	// 0
    22  }
    23  
    24  func ExampleLeadingZeros32() {
    25  	fmt.Println(bits.LeadingZeros32(0))
    26  	fmt.Println(bits.LeadingZeros32(1))
    27  	// Output:
    28  	// 32
    29  	// 31
    30  }
    31  
    32  func ExampleLeadingZeros64() {
    33  	fmt.Println(bits.LeadingZeros64(0))
    34  	fmt.Println(bits.LeadingZeros64(1))
    35  	// Output:
    36  	// 64
    37  	// 63
    38  }
    39  
    40  func ExampleOnesCount() {
    41  	fmt.Printf("%b\n", 14)
    42  	fmt.Println(bits.OnesCount(14))
    43  	// Output:
    44  	// 1110
    45  	// 3
    46  }
    47  
    48  func ExampleOnesCount8() {
    49  	fmt.Printf("%b\n", 14)
    50  	fmt.Println(bits.OnesCount8(14))
    51  	// Output:
    52  	// 1110
    53  	// 3
    54  }
    55  
    56  func ExampleOnesCount16() {
    57  	fmt.Printf("%b\n", 14)
    58  	fmt.Println(bits.OnesCount16(14))
    59  	// Output:
    60  	// 1110
    61  	// 3
    62  }
    63  
    64  func ExampleOnesCount32() {
    65  	fmt.Printf("%b\n", 14)
    66  	fmt.Println(bits.OnesCount32(14))
    67  	// Output:
    68  	// 1110
    69  	// 3
    70  }
    71  
    72  func ExampleOnesCount64() {
    73  	fmt.Printf("%b\n", 14)
    74  	fmt.Println(bits.OnesCount64(14))
    75  	// Output:
    76  	// 1110
    77  	// 3
    78  }