📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
/*function EncodeEnglish(s:String):String;
var
i,j,len:Integer;
cur:Integer;
t:String;
begin
Result:='';
len:=Length(s); //j 用于移位计数
i:=1;
j:=0;
while i<=len do
begin
if i<len then //数据变换
cur:=(ord(s[i]) shr j) or ((ord(s[i+1]) shl (7-j)) and $ff)
else
cur:=(ord(s[i]) shr j) and $7f;
FmtStr(t,'%2.2X',[cur]);
Result:=Result+t;
inc(i);
j:=(j+1) mod 7; //移位计数达到7位的特别处理
if j=0 then inc(i);
end;
end; */
void EncodeEnglish(char *psrc,char *pdes)
{
int i,j,len;
int cur;
char t[20];
len=strlen(psrc); //j 用于移位计数
i=0;
j=0;
while ( i<len )
{
if (i<len-1) //数据变换
cur=( (psrc[i]) >> j) | (((psrc[i+1]) << (7-j)) & 0xff) ;
else
cur=((psrc[i]) >> j) & 0x7f;
sprintf(t,"%2.2X",cur);
strcat(pdes,t);
i++;
j=(j+1) %7; //移位计数达到7位的特别处理
if (j==0 ) i++;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *psrc="6666";
char pdes[200];
memset(pdes,0,200);
EncodeEnglish(psrc,pdes) ;
Caption=pdes;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -