Golang hash/crc32.New and MakeTable functions example

package hash/crc32

New creates a new hash.Hash32 computing the CRC-32 checksum using the polynomial represented by the Table.

MakeTable returns the Table constructed from the specified polynomial.

Golang hash/crc32.New and MakeTable functions usage example

 package main

 import (
 "fmt"
 "hash/crc32"
 )

 var castagnoliTable = crc32.MakeTable(crc32.Castagnoli) // see http://golang.org/pkg/hash/crc32/#pkg-constants

 func main() {

 crc := crc32.New(castagnoliTable)
 crc.Write([]byte("abcd"))

 fmt.Printf("Sum32 : %x \n", crc.Sum32())

 }

Output :

Sum32 : 92c80a31

References :

http://golang.org/pkg/hash/crc32/#pkg-constants

http://golang.org/pkg/hash/crc32/#New

http://golang.org/pkg/hash/crc32/#MakeTable

Advertisement