求教做一函数将一个整数转换为BCD码
如12345转换为$012345谢谢
如12345转换为$012345谢谢
解决方案 »
- 头痛!这句始终报——语句的语法错误,错哪了?
- 招DELPHI开发人员(北京上地)
- 有什么工具快速删除delphi源代码的注释?
- 请大家帮我看看这句代码哪有问题,跟帖者有分!!
- 怎么在Detailband区域中显示的字段中写代码?如。。。。。
- 令我郁闷的问题!Error reading ktjypjfrm.Caption:
- 跪求一道pascal编程题 用过程不用函数
- 用DELPHI的都是一些比较菜的程序员的工具!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- dbgrid的dgmultiselect设为ture就可以在表格选择多条记录,我现在要将所选择记录的字段为(班级)的数据改为(初一年级)
- DELPHI 这是要王者归来的节奏吗?英巴卡迪诺新年战略:支持Linux【提供中文手册】
- 请问:那里有将DELPHI的代码转换为C代码的工具或代码?
- 有关局域网的一个问题(SQlServer有关)
不过看你问了,帮你搜索了一下,得到:
var i:integer;
p:pByte;
a:array[0..3] of byte;
begin
i:=1000;
p:=@i;
a[1]:=p^;
inc(p,1);
a[0]:=p^;
showmessage(inttoHex(a[0],1));
showmessage(inttoHex(a[1],1));
end;
你参考一下
http://community.csdn.net/Expert/topic/3492/3492471.xml?temp=.5220301
http://community.csdn.net/Expert/topic/3546/3546235.xml?temp=3.979129E-02
iTemp,iBCD:integer;begin
iTemp:=12345;
iBCD:=StrToInt('$'+IntToStr(iTemp));
我搞出来了
function ConvertBCD(m,n:integer):integer;
begin
result := 0;
result := result + ((m div 10) mod 10);
result := result shl 4;
result := result + (m mod 10);
dec(n);
if n=0 then exit;
result := result shl 4;
result := result + ((m div 1000) mod 10);
result := result shl 4;
result := result + ((m div 100) mod 10);
dec(n);
if n=0 then exit;
result := result shl 4;
result := result + ((m div 100000) mod 10);
result := result shl 4;
result := result + ((m div 10000) mod 10);
dec(n);
if n=0 then exit;
result := result shl 4;
result := result + ((m div 10000000) mod 10);
result := result shl 4;
result := result + ((m div 1000000) mod 10);
end;我要的是如 :1234567 变为 $01234567 不是 $67452301