unit Crc8;

interface

Uses
Classes, Windows; Function Crc_8n(p : array of BYTE; len : BYTE) : Byte; implementation Function Crc_8n(p : array of BYTE; len : BYTE) : Byte;
Var
j, cbit, aout, crc, crc_a, crc_b : Byte;
i : integer;
begin
crc := ;
i := ; // 取移位的位
repeat
crc_a := p[i];
inc(i);
j := ;
cbit := ;
repeat
crc_b := crc_a;
crc_b := crc_b xor crc; // ?????
aout := crc_b and cbit;
if aout<> then begin
crc := crc xor $; // ?????
crc := crc shr ;
crc := crc or $;
end else begin
crc := crc shr ;
end;
crc_a := crc_a shr ;
dec(j);
until j = ;
dec(len);
until len = ; result := crc;
end; end. ================================= unit main; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
Crc8; type
TForm1 = class(TForm)
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} const MinBase = ;
MaxBase = ; function StrToNum (const s: string; base: Integer;
neg: Boolean; max: Integer): Integer;
// s = 要转换的字符串
// base = 进制数
// neg = 是否为负数 // max = 要转换的最大数//
// 用法:
// i:= StrToNum ('''''''''''''''', , false, MaxInt);
// i:= StrToNum (''''''''002D'''''''', , false, MaxInt);
// i:= StrToNum (''''''''-'''''''', , true, MaxInt);
// i:= StrToNum (''''''''ZZ'''''''', , true, MaxInt);
//
var negate, done: Boolean;
i, len, digit, mmb: Integer;
c: Char;
mdb, res: Integer;
begin
res:= ; i:= ; digit:= ;
if (base >= MinBase) and (base <= MaxBase) then begin
mmb:= max mod base;
mdb:= max div base;
len:= Length (s);
negate:= False;
while (i <= len) and (s[i] = '''' '''') do Inc (i);
if neg then begin
case s[i] of
'''' '''': Inc (i);
''''-'''': begin Inc (i); negate:= TRUE; end;
end; (* CASE *)
end; (* IF neg *)
done:= len > i;
while (i <= len) and done do begin
c:= Upcase (s[i]);
case c of
''''''''..'''''''': digit:= ORD(c) - ;
''''A''''..''''Z'''': digit:= ORD(c) - ;
else done:= FALSE
end; (* CASE *)
done:= done and (digit < base);
if done then begin
done:= (res < mdb) or ((res = mdb) and (digit <= mmb));
IF done then begin
res:= res * base digit;
Inc (i);
end; (* IF done *)
end; (* IF done *)
end; (* WHILE *)
if negate then res:= - res;
end; (* IF done *)
Result:= res;
end; procedure TForm1.Button1Click(Sender: TObject);
Var
S : String;
P : Array[..] of Byte;
Len : Byte;
R : Byte;
I : Integer;
begin
S := Edit1.Text; if length(s) mod = then s := s ''''''''; Memo1.Lines.Add(S '''' :'''');
for i:= to length(s) div do begin
p[i-] := BYTE(StrToNum(copy(s, (i-)* , ), , false, ));
Memo1.Lines.Add(IntToStr(I) '''' --> '''' IntToHex(p[i-], ));
end; Len := length(s) div ; R := Crc_8n(P, Len);
Memo1.Lines.Add(''''Crc8 Result: '''' IntToHex(R, ));
end; end.

CRC8算法DELPHI源码的更多相关文章

  1. SURF算法与源码分析、下

    上一篇文章 SURF算法与源码分析.上 中主要分析的是SURF特征点定位的算法原理与相关OpenCV中的源码分析,这篇文章接着上篇文章对已经定位到的SURF特征点进行特征描述.这一步至关重要,这是SU ...

  2. [源码]Delphi源码免杀之函数动态调用 实现免杀的下载者

    [免杀]Delphi源码免杀之函数动态调用 实现免杀的下载者 2013-12-30 23:44:21         来源:K8拉登哥哥's Blog   自己编译这份代码看看 过N多杀软  没什么技 ...

  3. QQ2008自动聊天精灵delphi源码

    QQ2008自动聊天精灵delphi源码   unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Grap ...

  4. 转换GMT秒数为日期时间格式-Delphi源码

    转换GMT秒数为日期时间格式-Delphi源码.收藏最近在写PE分析工具的时候,需要转换TimeDateStamp字段值为日期时间格式,这是Delphi的源码. //把GMT时间的秒数转换成日期时间格 ...

  5. GWO(灰狼优化)算法MATLAB源码逐行中文注解(转载)

    以优化SVM算法的参数c和g为例,对GWO算法MATLAB源码进行了逐行中文注解. tic % 计时器 %% 清空环境变量 close all clear clc format compact %% ...

  6. http代理工具delphi源码

    http://www.caihongnet.com/content/xingyexinwen/2013/0721/730.html http代理工具delphi源码 以下代码在 DELPHI7+IND ...

  7. SURF算法与源码分析、上

    如果说SIFT算法中使用DOG对LOG进行了简化,提高了搜索特征点的速度,那么SURF算法则是对DoH的简化与近似.虽然SIFT算法已经被认为是最有效的,也是最常用的特征点提取的算法,但如果不借助于硬 ...

  8. 三种排序算法python源码——冒泡排序、插入排序、选择排序

    最近在学习python,用python实现几个简单的排序算法,一方面巩固一下数据结构的知识,另一方面加深一下python的简单语法. 冒泡排序算法的思路是对任意两个相邻的数据进行比较,每次将最小和最大 ...

  9. 6种基础排序算法java源码+图文解析[面试宝典]

    一.概述 作为一个合格的程序员,算法是必备技能,特此总结6大基础算法.java版强烈推荐<算法第四版>非常适合入手,所有算法网上可以找到源码下载. PS:本文讲解算法分三步:1.思想2.图 ...

随机推荐

  1. crontab机会任务监控

    <1>如何查看自己的计划任务是否成功的执行? 昨天crontab中的同步任务没有执行,不知道是什么原因没有执行,貌似任务hang住了,想查询一下crontab到底问题出在哪里,或者hang ...

  2. apache+php windows下配置

    2014年1月9日 13:58:54 现在PHP大部分是vc9编译的,其扩展在windows下大部分也都是用vc9编译的(memcache,xdebuge...),,所以要想Apache+PHP+PH ...

  3. 点击超链接打开本地QQ

    2014年6月4日 10:20:18 张志斌 这个功能实际上是属于腾讯的推广项目"一键加群"功能: http://qun.qq.com/join.html 用户必须有自己的群,登录 ...

  4. python基础类型 —— Sets集合

    集合(set)是一个无序不重复元素的序列. 基本功能是进行成员关系测试和删除重复元素. 运行结果如下: sets其他操作: myset.add('x') # 添加一项 myset.update([10 ...

  5. libsvm的使用

    参考:http://www.cnblogs.com/GuoJiaSheng/p/4480497.html http://www.cnblogs.com/tornadomeet/archive/2012 ...

  6. c++中的前置声明

    引用google c++编码规范: When you include a header file you introduce a dependency that will cause your cod ...

  7. 二维码生成delphi版

    二维码生成delphi版 生成二维码的软件,代码从C语言转换过来(源地址:http://fukuchi.org/works/qrencode/),断断续续的差不多花了一周时间来转换和调试.在转换过程中 ...

  8. java学习之借书系统

    实现的图书借阅系统要处理用户输入的非法参数,并引导用户正确使用 测试结果: 主要目的就是练习异常处理中的Exception类的使用 使用的相关语法 try{ //可能产生异常的代码块 }catch(E ...

  9. Python - 列表与字符串的互相转换

    题目:请将text字符串中的数字取出,并输出成一个新的字符串 text = "aAsmr3 idd4bgs7Dlsf 9eAF" b = list(text) new_list = ...

  10. Java异常类层次结构图

    1. 分类图镇楼: 2.运行时异常与非运行时异常区别: Java 提供了两类主要的异常 :runtime exception 和 checked exception. 2.1 checked exce ...