github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/third_party/gofrontend/libgo/go/hash/crc32/example_test.go (about)

     1  // Copyright 2015 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  // +build ignore
     6  
     7  package crc32_test
     8  
     9  import (
    10  	"fmt"
    11  	"hash/crc32"
    12  )
    13  
    14  func ExampleMakeTable() {
    15  	// In this package, the CRC polynomial is represented in reversed notation,
    16  	// or LSB-first representation.
    17  	//
    18  	// LSB-first representation is a hexadecimal number with n bits, in which the
    19  	// most significant bit represents the coefficient of x⁰ and the least significant
    20  	// bit represents the coefficient of xⁿ⁻¹ (the coefficient for xⁿ is implicit).
    21  	//
    22  	// For example, CRC32-Q, as defined by the following polynomial,
    23  	//	x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰
    24  	// has the reversed notation 0b11010101100000101000001010000001, so the value
    25  	// that should be passed to MakeTable is 0xD5828281.
    26  	crc32q := crc32.MakeTable(0xD5828281)
    27  	fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q))
    28  	// Output:
    29  	// 2964d064
    30  }