求高手 Delphi 代码转 c#

cs_op cs_op 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

//这是一个函数
function StrTOBcd(Str: string): string;
var
aa, n,i, Bytes: Byte;
Odd: boolean;
hex1,Hex: string;
begin
str := trim(str); //去空格和回车等特殊字符
str := stringreplace(str, ' ', '', [rfReplaceAll]);
Result := '';
Odd := Length(Str) mod 2 = 1;
Bytes := (Length(Str) + 1) div 2;
if Odd then Str := Str + '0';
for i := 0 to Bytes - 1 do
begin
Hex := Copy(Str, i * 2 + 1, 2);
//ShowMessage(chr(01));
Result := Result + chr(HexToInt(Hex));
end;
end;







//另一个
function BcdTOstr(ss: string): string;
var
i: integer;
s, s2: string;
begin
for i := 1 to length(ss) do
begin
s2 := ss[i];
s := s + BCD2Str(pchar(s2), 0, 2);
end;
result := s;
end;


function BCD2Str(P: PChar; Pos, Len: integer): string;
var
i: integer;
strResult: string;
cRead: Byte;
cReadH, cReadL: Byte;
bOdd: boolean;
begin
strResult := '';
if (Len mod 2) = 1 then
begin
Len := (Len + 1) div 2;
bOdd := true;
end else begin
Len := Len div 2;
bOdd := false;
end;
for i := 0 to Len - 1 do
begin
cRead := Ord(P[pos + i]);
cReadH := (cRead and $F0) shr 4;
strResult := strResult + IntToHex(cReadH, 1);
if (i = Len - 1) and bOdd then continue;
cReadL := cRead and $0F;
strResult := strResult + IntToHex(cReadL, 1);
end;
BCD2Str := strResult;
end;




...全文
评论 3
收藏 已收藏
分享
返回顶部
cs_op
C# 111,128 成员 642,536 内容