From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c86eb13dd395066 X-Google-Attributes: gid103376,public From: dbrown@vigra.com (David Brown) Subject: Re: CRC in Ada? Date: 1997/03/03 Message-ID: #1/1 X-Deja-AN: 222782609 Sender: dbrown@ted.vigra.com References: <1997Mar2.220652@nova.wright.edu> Organization: VisiCom Laboratories, Inc. Newsgroups: comp.lang.ada Date: 1997-03-03T00:00:00+00:00 List-Id: jmatthews@nova.wright.edu (Dr. John B. Matthews) writes: > Hi! Can anyone point me to 16-bit CRC code in Ada? I've checked the > PAL and several other archives without luck. Any help appreciated. I threw this together the other day. I declare this code to be public domain. Please give it a try, but I offer no guarantees that this works. David Brown dbrown@vigra.com ---------------------------------------------------------------------- package Data is type Byte is mod 2 ** 8; for Byte'Size use 8; type Byte_Array is array (Positive range <>) of Byte; end Data; ---------------------------------------------------------------------- with Data; use Data; package Crc16 is type U16 is mod 2 ** 16; procedure Update (Crc : in out U16; Data : in Byte_Array); end Crc16; ---------------------------------------------------------------------- package body Crc16 is type U16_Array is array (Byte) of U16; -- The generated lookup table. Table : U16_Array; procedure Update (Crc : in out U16; Data : in Byte_Array) is begin for I in Data'Range loop Crc := (Crc / 16#100#) xor Table (Byte (Crc) xor Data (I)); end loop; end Update; -- Generate the lookup table. procedure Generate is P : constant := 16#8408#; V : U16; begin for B in Byte loop V := U16 (B); for I in 1 .. 8 loop if (V and 1) = 0 then V := V / 2; else V := (V / 2) xor P; end if; end loop; Table (B) := V; end loop; end Generate; begin Generate; end Crc16; ----------------------------------------------------------------------