CRC8算法DELPHI源码
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源码的更多相关文章
- SURF算法与源码分析、下
上一篇文章 SURF算法与源码分析.上 中主要分析的是SURF特征点定位的算法原理与相关OpenCV中的源码分析,这篇文章接着上篇文章对已经定位到的SURF特征点进行特征描述.这一步至关重要,这是SU ...
- [源码]Delphi源码免杀之函数动态调用 实现免杀的下载者
[免杀]Delphi源码免杀之函数动态调用 实现免杀的下载者 2013-12-30 23:44:21 来源:K8拉登哥哥's Blog 自己编译这份代码看看 过N多杀软 没什么技 ...
- QQ2008自动聊天精灵delphi源码
QQ2008自动聊天精灵delphi源码 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Grap ...
- 转换GMT秒数为日期时间格式-Delphi源码
转换GMT秒数为日期时间格式-Delphi源码.收藏最近在写PE分析工具的时候,需要转换TimeDateStamp字段值为日期时间格式,这是Delphi的源码. //把GMT时间的秒数转换成日期时间格 ...
- GWO(灰狼优化)算法MATLAB源码逐行中文注解(转载)
以优化SVM算法的参数c和g为例,对GWO算法MATLAB源码进行了逐行中文注解. tic % 计时器 %% 清空环境变量 close all clear clc format compact %% ...
- http代理工具delphi源码
http://www.caihongnet.com/content/xingyexinwen/2013/0721/730.html http代理工具delphi源码 以下代码在 DELPHI7+IND ...
- SURF算法与源码分析、上
如果说SIFT算法中使用DOG对LOG进行了简化,提高了搜索特征点的速度,那么SURF算法则是对DoH的简化与近似.虽然SIFT算法已经被认为是最有效的,也是最常用的特征点提取的算法,但如果不借助于硬 ...
- 三种排序算法python源码——冒泡排序、插入排序、选择排序
最近在学习python,用python实现几个简单的排序算法,一方面巩固一下数据结构的知识,另一方面加深一下python的简单语法. 冒泡排序算法的思路是对任意两个相邻的数据进行比较,每次将最小和最大 ...
- 6种基础排序算法java源码+图文解析[面试宝典]
一.概述 作为一个合格的程序员,算法是必备技能,特此总结6大基础算法.java版强烈推荐<算法第四版>非常适合入手,所有算法网上可以找到源码下载. PS:本文讲解算法分三步:1.思想2.图 ...
随机推荐
- LTE:eMBMS架构
一个MBSFN区域是由一个或多个传输相同内容的小区组成的特殊区域.如图1所示,小区8和9都属于MBSFN区域C.一个MBSFN区域可由多个小区组成,一个小区也可以属于多个(至多8个,从36.331中的 ...
- [原创]win7环境下搭建eclipse+python+django开发环境
一)工具下载 a)eclipse(最新版4.3.1)官网下载地址 http://www.eclipse.org/downloads/ b)python (2.X版本)官网下载地址 http://pyt ...
- Babel(抽象语法树,又称AST)
文章:https://juejin.im/post/5a9315e46fb9a0633a711f25 https://github.com/jamiebuilds/babel-handbook/blo ...
- Error updating database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String异常处理
问题原因:Mybatis中对于时间参数进行比较时的一个BUG. 如果拿传入的时间类型参数与空字符串‘‘进行对比判断则会引发异常.,所以应该去掉该判断, 只保留非空判断就正常了 <if test= ...
- 打开文件或者uri的方式--------进程启动文件和启动者启动文件
The Process class in System.Diagnostics allows you to launch a new process.For security reasons, t ...
- selenium 操作文本框(textarea输入)
selenium 对文本框的输入操作一般有两种形式,传统的是直接通过定位元素通过sendKeys()方法直接在文本框中输入信息.但有时候我们可以通过id 的方式将其进行定位,但却不能通过sendKey ...
- FreeMarker使用小记(HelloWorld)
FreeMarker是开源的模板框架.对于它的介绍网上已经很多了.详情可参考主页:http://www.freemarker.org/ 现在我们就开始我们的FreeMarker版的Hello Worl ...
- KnockoutJs学习笔记(八)
with binding用于创建一个新的绑定环境(binding context),包含with binding的元素的所有子元素都将处于指定的object的环境限定内. 下面是一个简单的使用with ...
- 判断js数组/对象是否为空
/** * 判断js数组/对象是否为空 * isPrototypeOf() 验证一个对象是否存在于另一个对象的原型链上.即判断 Object 是否存在于 $obj 的原型链上.js中一切皆对象,也就是 ...
- Vue之双向绑定原理动手记
Vue.js的核心功能有两个:一是响应式的数据绑定系统,二是组件系统.本文是通过学习他人的文章,从而理解了双向绑定原理,从而在自己理解的基础上,自己动手实现数据的双向绑定. 目前几种主流的mvc(vm ...