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. Ansible Tower系列 三(使用tower执行一个任务)【转】

    创建playbook Tower playbook 项目默认存在 /var/lib/awx/projects/ su - awx cd projects/ mkdir ansible-for-devo ...

  2. XShell 使用方法

    XShell是一款Windows下非常优秀的远程连接Linux主机的工具,是平常使用不可缺少的工具.复制和粘贴由于在linux的Shell下,Ctrl+c是中断当前指令,这个快捷键和win系统下的复制 ...

  3. URL传递的参数是UTF-8编码,在打开的页面正常显示(GB2312)的方法

    URL传递的参数采用的是UTF-8编码,在打开的子页面中显示乱码, URL传递的地址形如:http://localhost/test.aspx?orgname=%E5%8B%**%**%**%**&a ...

  4. Android 5.0 行为变更

    Android 5.0 除了提供诸多新特性和功能外,还对系统和 API 行为做出了各种变更.本文重点介绍您应该了解并在开发应用时加以考虑的一些主要变更. 如果您之前发布过 Android 应用,请注意 ...

  5. 一份可以发布jar包到MAVEN中央仓库的POM

    [2017-01-03 更新]将基础的pom抽离成一个项目无关的parent pom,euler-framework的pom继承这个parent pom 今天在家折腾了一下怎么把Jar包发布到Mave ...

  6. Nginx配置支持https协议-应用实践

    Nginx配置支持https协议-应用实践 https简介 HTTPS 是运行在 TLS/SSL 之上的 HTTP,与普通的 HTTP 相比,在数据传输的安全性上有很大的提升. TLS是传输层安全协议 ...

  7. Webpack vs Gulp

    Webpack vs Gulp 谁会被拍死在沙滩上   本文组织结构 理想的前端开发流程 Gulp 为何物 Webpack 又是从哪冒出来的 结论 文章有点长,总共 1800 字,阅读需要 18 分钟 ...

  8. 【LeetCode】151. Reverse Words in a String

    Difficulty: Medium  More:[目录]LeetCode Java实现 Description Given an input string, reverse the string w ...

  9. 全局查询文件linux

    在工作中,可能突然需要找到某个文件,这个又不知道,需要全局查询一下. 下面是命令行: find / -name "*.log" | xargs grep "elk&quo ...

  10. 单页面vue引入百度统计的使用方法!

    最近组长安排着做一个项目,h5的应用下载项目,想着做起来还是比较容易,可是看到提出的需求,我就有点懵逼了!需要对应用的下载进行统计!!!我当时就想着我前端怎么对页面点击按钮就行数据统计啊!我以前的项目 ...