...
Run Format

Source file src/math/bits/example_test.go

Documentation: math/bits

     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  // Code generated by go run make_examples.go. DO NOT EDIT.
     6  
     7  package bits_test
     8  
     9  import (
    10  	"fmt"
    11  	"math/bits"
    12  )
    13  
    14  func ExampleLeadingZeros8() {
    15  	fmt.Printf("LeadingZeros8(%08b) = %d\n", 1, bits.LeadingZeros8(1))
    16  	// Output:
    17  	// LeadingZeros8(00000001) = 7
    18  }
    19  
    20  func ExampleLeadingZeros16() {
    21  	fmt.Printf("LeadingZeros16(%016b) = %d\n", 1, bits.LeadingZeros16(1))
    22  	// Output:
    23  	// LeadingZeros16(0000000000000001) = 15
    24  }
    25  
    26  func ExampleLeadingZeros32() {
    27  	fmt.Printf("LeadingZeros32(%032b) = %d\n", 1, bits.LeadingZeros32(1))
    28  	// Output:
    29  	// LeadingZeros32(00000000000000000000000000000001) = 31
    30  }
    31  
    32  func ExampleLeadingZeros64() {
    33  	fmt.Printf("LeadingZeros64(%064b) = %d\n", 1, bits.LeadingZeros64(1))
    34  	// Output:
    35  	// LeadingZeros64(0000000000000000000000000000000000000000000000000000000000000001) = 63
    36  }
    37  
    38  func ExampleTrailingZeros8() {
    39  	fmt.Printf("TrailingZeros8(%08b) = %d\n", 14, bits.TrailingZeros8(14))
    40  	// Output:
    41  	// TrailingZeros8(00001110) = 1
    42  }
    43  
    44  func ExampleTrailingZeros16() {
    45  	fmt.Printf("TrailingZeros16(%016b) = %d\n", 14, bits.TrailingZeros16(14))
    46  	// Output:
    47  	// TrailingZeros16(0000000000001110) = 1
    48  }
    49  
    50  func ExampleTrailingZeros32() {
    51  	fmt.Printf("TrailingZeros32(%032b) = %d\n", 14, bits.TrailingZeros32(14))
    52  	// Output:
    53  	// TrailingZeros32(00000000000000000000000000001110) = 1
    54  }
    55  
    56  func ExampleTrailingZeros64() {
    57  	fmt.Printf("TrailingZeros64(%064b) = %d\n", 14, bits.TrailingZeros64(14))
    58  	// Output:
    59  	// TrailingZeros64(0000000000000000000000000000000000000000000000000000000000001110) = 1
    60  }
    61  
    62  func ExampleOnesCount8() {
    63  	fmt.Printf("OnesCount8(%08b) = %d\n", 14, bits.OnesCount8(14))
    64  	// Output:
    65  	// OnesCount8(00001110) = 3
    66  }
    67  
    68  func ExampleOnesCount16() {
    69  	fmt.Printf("OnesCount16(%016b) = %d\n", 14, bits.OnesCount16(14))
    70  	// Output:
    71  	// OnesCount16(0000000000001110) = 3
    72  }
    73  
    74  func ExampleOnesCount32() {
    75  	fmt.Printf("OnesCount32(%032b) = %d\n", 14, bits.OnesCount32(14))
    76  	// Output:
    77  	// OnesCount32(00000000000000000000000000001110) = 3
    78  }
    79  
    80  func ExampleOnesCount64() {
    81  	fmt.Printf("OnesCount64(%064b) = %d\n", 14, bits.OnesCount64(14))
    82  	// Output:
    83  	// OnesCount64(0000000000000000000000000000000000000000000000000000000000001110) = 3
    84  }
    85  
    86  func ExampleRotateLeft8() {
    87  	fmt.Printf("%08b\n", 15)
    88  	fmt.Printf("%08b\n", bits.RotateLeft8(15, 2))
    89  	fmt.Printf("%08b\n", bits.RotateLeft8(15, -2))
    90  	// Output:
    91  	// 00001111
    92  	// 00111100
    93  	// 11000011
    94  }
    95  
    96  func ExampleRotateLeft16() {
    97  	fmt.Printf("%016b\n", 15)
    98  	fmt.Printf("%016b\n", bits.RotateLeft16(15, 2))
    99  	fmt.Printf("%016b\n", bits.RotateLeft16(15, -2))
   100  	// Output:
   101  	// 0000000000001111
   102  	// 0000000000111100
   103  	// 1100000000000011
   104  }
   105  
   106  func ExampleRotateLeft32() {
   107  	fmt.Printf("%032b\n", 15)
   108  	fmt.Printf("%032b\n", bits.RotateLeft32(15, 2))
   109  	fmt.Printf("%032b\n", bits.RotateLeft32(15, -2))
   110  	// Output:
   111  	// 00000000000000000000000000001111
   112  	// 00000000000000000000000000111100
   113  	// 11000000000000000000000000000011
   114  }
   115  
   116  func ExampleRotateLeft64() {
   117  	fmt.Printf("%064b\n", 15)
   118  	fmt.Printf("%064b\n", bits.RotateLeft64(15, 2))
   119  	fmt.Printf("%064b\n", bits.RotateLeft64(15, -2))
   120  	// Output:
   121  	// 0000000000000000000000000000000000000000000000000000000000001111
   122  	// 0000000000000000000000000000000000000000000000000000000000111100
   123  	// 1100000000000000000000000000000000000000000000000000000000000011
   124  }
   125  
   126  func ExampleReverse8() {
   127  	fmt.Printf("%08b\n", 19)
   128  	fmt.Printf("%08b\n", bits.Reverse8(19))
   129  	// Output:
   130  	// 00010011
   131  	// 11001000
   132  }
   133  
   134  func ExampleReverse16() {
   135  	fmt.Printf("%016b\n", 19)
   136  	fmt.Printf("%016b\n", bits.Reverse16(19))
   137  	// Output:
   138  	// 0000000000010011
   139  	// 1100100000000000
   140  }
   141  
   142  func ExampleReverse32() {
   143  	fmt.Printf("%032b\n", 19)
   144  	fmt.Printf("%032b\n", bits.Reverse32(19))
   145  	// Output:
   146  	// 00000000000000000000000000010011
   147  	// 11001000000000000000000000000000
   148  }
   149  
   150  func ExampleReverse64() {
   151  	fmt.Printf("%064b\n", 19)
   152  	fmt.Printf("%064b\n", bits.Reverse64(19))
   153  	// Output:
   154  	// 0000000000000000000000000000000000000000000000000000000000010011
   155  	// 1100100000000000000000000000000000000000000000000000000000000000
   156  }
   157  
   158  func ExampleReverseBytes16() {
   159  	fmt.Printf("%016b\n", 15)
   160  	fmt.Printf("%016b\n", bits.ReverseBytes16(15))
   161  	// Output:
   162  	// 0000000000001111
   163  	// 0000111100000000
   164  }
   165  
   166  func ExampleReverseBytes32() {
   167  	fmt.Printf("%032b\n", 15)
   168  	fmt.Printf("%032b\n", bits.ReverseBytes32(15))
   169  	// Output:
   170  	// 00000000000000000000000000001111
   171  	// 00001111000000000000000000000000
   172  }
   173  
   174  func ExampleReverseBytes64() {
   175  	fmt.Printf("%064b\n", 15)
   176  	fmt.Printf("%064b\n", bits.ReverseBytes64(15))
   177  	// Output:
   178  	// 0000000000000000000000000000000000000000000000000000000000001111
   179  	// 0000111100000000000000000000000000000000000000000000000000000000
   180  }
   181  
   182  func ExampleLen8() {
   183  	fmt.Printf("Len8(%08b) = %d\n", 8, bits.Len8(8))
   184  	// Output:
   185  	// Len8(00001000) = 4
   186  }
   187  
   188  func ExampleLen16() {
   189  	fmt.Printf("Len16(%016b) = %d\n", 8, bits.Len16(8))
   190  	// Output:
   191  	// Len16(0000000000001000) = 4
   192  }
   193  
   194  func ExampleLen32() {
   195  	fmt.Printf("Len32(%032b) = %d\n", 8, bits.Len32(8))
   196  	// Output:
   197  	// Len32(00000000000000000000000000001000) = 4
   198  }
   199  
   200  func ExampleLen64() {
   201  	fmt.Printf("Len64(%064b) = %d\n", 8, bits.Len64(8))
   202  	// Output:
   203  	// Len64(0000000000000000000000000000000000000000000000000000000000001000) = 4
   204  }
   205  

View as plain text