中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
GSM规范中的部分编码转换
作者:佚名 时间:2007-09-20 16:07 出处:互连网 责编:月夜寒箫
              摘要:GSM规范中的部分编码转换

在做跟手机短信相关的东东时候常遇到各种编码格式数据的转换,特写了几个函数,供参考。

function EncodeEnglish(var 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);

//移位计数达到7位的特别处理

j:=(j+1) mod 7;

if j=0 then inc(i);

end;

end;

//end;

function BinaryUniCode2Gb2312(ABinaryString:PChar;APosStart,APosEnd:integer):string;

var

i,iLen:integer;

AscHexText,TmpHexStr:string;

AsciiInt:integer ;

AscLen,AscUniLen:integer;

UniHexstr,GB2312:string;

begin

iLen:=Length(ABinaryString);

for i:= APosStart-1 to APosEnd-1 do

begin

AsciiInt:=ord(ABinaryString[i]);

TmpHexStr:=Format('%x',[AsciiInt]);

if length(TmpHexStr)=1 then

TmpHexStr:='0'+TmpHexStr;

AscHexText:=AscHexText+TmpHexStr;

end; //for

AscLen:=Length(AscHexText);

AscUniLen:=AscLen div 4;

for i:=0 to AscUniLen-1 do

begin

UniHexstr:=Copy(AscHexText,i*4+1,4);

// Gb2312 := Gb2312 + UnicodeToGb2312(HexAscii2DecimalInt(uniHexstr));

end; // for

result := Gb2312 ;

end;

function WideStringToUnicode_Ex(s:WideString;ADestStr:PChar;Limit:integer):integer;

var sLen:integer;

buffer:array[1..1024] of char;

tmpchar:char;

i:integer;

begin

sLen:=Length(s);

if sLen>0 then

begin

CopyMemory(@buffer,Pointer(s),2*SLen);

for i:=0 to SLen-1 do

begin

tmpchar:=buffer[2*i+1];

buffer[2*i+1]:=buffer[2*i+2];

buffer[2*i+2]:=tmpchar;

end;

if SLen>Limit then

SLen:=Limit;

CopyMemory(ADestStr,@buffer,2*SLen);

result:=SLen*2;

result:=2*SLen;

end

else

begin

result:=0;

end;

end;

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有