bcb中有没有delphi中的函数chr() 和ord()
我想在BCB中改写DLEHI的代码成C的但是 对这两个函数不知道怎么转换
chr()是把数字转换成字符
ord()是把字符转换成数字
在DELPHI中
Source :string ;
ind : dword;
a2 : byte
ord(Source[Count+1]) - $41
chr(ind or a2);
我
转换成C
AnsiSting Source;
DWORD ind;
BYTE a2;
XX(Source[Count+1]-0x41
xxx(ind | a1)
帮我把这个两个地方搞定 谢谢了
问题点数:0、回复次数:9Top
1 楼yingyys(鹰)回复于 2003-06-04 09:03:00 得分 0
StrToInt(Source[Count+1])-0x41
IntToStr(ind | a1)
Top
2 楼COKING(天晴)回复于 2003-06-04 09:22:45 得分 0
呵呵!!!!
char x='a';
int y=x; // y=97
y=98;
x=y; //x='b'
Top
3 楼Behard(我爱天安门)回复于 2003-06-04 10:22:16 得分 0
直接强制转换即可Top
4 楼wyouken(无心の伤你)回复于 2003-06-04 11:38:42 得分 0
怎么强制转换由于我需要转换的位数比较多
我用StrToInt(Source[Count+1])-0x41
当Source[Count+1])=m时 程序会出错说是m不是一个整形变量
Top
5 楼dingzhenhhy(霸王龙)回复于 2003-06-04 11:53:40 得分 0
m是哪里来的?
好像你的Source[Count+1]不是整形,如果你的m定义的是int那么你要
Source[Count+1]=IntToStr(m);Top
6 楼ghiewa(阿漠)回复于 2003-06-04 12:16:41 得分 0
方法1:使用函数 IntToStr()和StrToInt();
方法2:运用强制类型转换 AnsiString(Source[Count+1]-0x41)和 Int()Top
7 楼wyouken(无心の伤你)回复于 2003-06-05 13:42:43 得分 0
我自己做了两个函数
char TForm1::chr(int m)
{
char temp;
temp=m;
return temp;
//TODO: Add your source code here
}
int TForm1::ord(char s)
{
int temp;
temp=s;
return temp; //TODO: Add your source code here
}
能达到我的效果但是有个问题 当我输入中文字符时比如“我”它的字符码是
0xce 0xd2
当我用
AnsiString s;
s=Memo1->Lines->Text;
int t=ord(s[1]) ;
Edit1->Text=IntToHex(t,2);
我用ord 函数得到得结果是负数是FFFFFFCE我想只得到CE怎么办呢
强制转换得方法是不行得
当我用
Edit1->Text=StrToInt(s[1]);或者
Edit1->Text=StrToInt(s);
会出现错误程序中断说字符不是一个可有效的整形变量(is not a valid integer value)Top
8 楼wyouken(无心の伤你)回复于 2003-06-06 07:26:12 得分 0
这样做能成功
s[1]&0xff不知道为什么
Top
9 楼teatool(美貌与智慧并重,英雄与侠义的化身)回复于 2003-06-06 08:58:08 得分 0
unsigned intTop



