5 people like it.

CRC16

simple CRC16

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
let Crc16 msg =
    let polynomial      = 0xA001us
    let mutable code    = 0xffffus
    for b in msg do
        code <- code ^^^ uint16 b
        for j in [0..7] do
            if (code &&& 1us <> 0us) then
                code <- (code >>> 1) ^^^ polynomial
            else
                code <- code >>> 1
    code
val Crc16 : msg:seq<int> -> uint16

Full name: Script.Crc16
val msg : seq<int>
val polynomial : uint16
val mutable code : uint16
val b : int
Multiple items
val uint16 : value:'T -> uint16 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.uint16

--------------------
type uint16 = System.UInt16

Full name: Microsoft.FSharp.Core.uint16
val j : int
Raw view Test code New version

More information

Link:http://fssnip.net/8z
Posted:13 years ago
Author:nCdy
Tags: crc