github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/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  package crc32_test
     6  
     7  import (
     8  	"github.com/shogo82148/std/fmt"
     9  	"github.com/shogo82148/std/hash/crc32"
    10  )
    11  
    12  func ExampleMakeTable() {
    13  	// このパッケージでは、CRCポリノミアルは逆順記法、またはLSB-firstの表現で表されます。
    14  	//
    15  	// LSB-first表現は、nビットの16進数であり、最上位ビットはx⁰の係数を表し、最下位ビットはxⁿ⁻¹(xⁿの係数は暗黙的に表される)の係数を表します。
    16  	//
    17  	// たとえば、以下のポリノミアルによって定義されるCRC32-Qは、次のような逆順記法を持ちます。
    18  	//	x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰
    19  	// したがって、MakeTableに渡すべき値は0xD5828281です。
    20  	crc32q := crc32.MakeTable(0xD5828281)
    21  	fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q))
    22  	// Output:
    23  	// 2964d064
    24  }