............... (50分)

B

bluely

Unregistered / Unconfirmed
GUEST, unregistred user!
............................
 
要是位数固定,就可以这样

tmp := $5da112e3;
tmp1 := tmp and $ffc00000;
tmp2 := tmp and $003fffff;
tmp := tmp1 shr 22 + tmp shl 10;

位数不定则要加一些判断
 
用嵌入汇编!

asm

mov eax,xxxxx
rol eax,10

end;
 
没必要那么麻烦:

var
tmp:longword;
const k:integer=10;
begin
tmp:=$5da112e3;
tmp:=(tmp shl k)+(tmp shr (32-k));
end;

这样指定k为位数就可以了,没什么原理。

另外,汇编也可以:
asm
mov eax,$5da112e3
rol eax,10
mov tmp,eax
end;

但指定位数就不那么容易了。
 
抱歉,有个问题没说明,在k=0或32时,
就不必这样做,否则会有错误,因为
tmp shl 32和shr 32都会返回tmp而不是0。
而此时汇编的rol仍然正确。
 
再次抱歉,又来了,只要把前面那段程序中的

tmp:=(tmp shl k)+(tmp shr (32-k))改为
tmp:=(tmp shl k) or (tmp shr (32-k))
就一切OK了,不必考虑在k=0或32时的问题,
这样我的程序总算比汇编程序好了。

希望不要有下一次 :-(
 
谢谢大家帮助,最后还有个问题,为什么我直接
tmp:=tmp shl 10算出来会偏差呢,我主要就是搞不东这个,谢谢
 
你移过的位都补成0了,那原来的是1的变成了0,岂不就有误差啦。
 
呵呵,汇编基础没打好吧
 
Delphi中没有循环移位,shl,shr都是简单移位。
 
谢谢大家!
 
.....................
 
顶部