现在在做一个程序,需要把别人写的一段JAVASCRIPT加密算法转过来在位运算符的问题上出现了很多问题,虽然程序能执行,但是结果老是不对所以我觉得我转换出错了,所以就想知道javascript中的<< >> >>>这个几个位运算符到底应该如何转换成object pascal中的运算符呢??如a << b改怎么转换是 a shl b吗?a >> b 就是 a shr b吗?那a >>> b呢???希望有十分懂的人给出一个正确的解答!谢谢了
解决方案 »
- alphacontrols控件输出exe程序没有皮肤怎么办?
- 三层中,Client端线程调用AppServer中函数的问题
- Delphi编译提示[fatal error]file not found:'ExceptionLog.dcu'
- 女友生日,放分300!
- 集合问题(简单)
- 高分求解,HELP!!!
- 请问各位高手,怎样才能使BDE管理器和oracle9i链接?
- 关于保存控件的问题(偶等了一下午,5555...):程序关闭后,怎么保持修改后的控件?分不够再加!
- 怎么给TListBox加水平滚动条,送20分
- C++Build VS Delphi *$^&#@*()
- BPL文件问题 在线等待
- 创建paradox数据表出错?Capability not supported.
>>把二进制右移,左边补和最高位相同的数字
对于>>,需要在shr后,在左边补和最高位相同的数字
a:Integer;
begin
a shr 1;
end;
对于> > :
function ShrEx(iSource, i: integer):integer;
var
j: integer;
begin
result := 0;
iSource := iSource shr i;
if iSource >= 0 then
result := iSource
else
begin
for j:=1 to i do
result := result + (1 shl (32-j));
result := iSource and rusult;
end;
end;
全都对应object pascal的shr即可
你用shr和shl即可.
<<<对应shl
<<和>>在Delphi中没有操作符对应.可以写成函数.
内嵌汇编版本的函数
Function LShl(Value : Cardinal; Bit : Byte):Integer; register;
asm
mov cl, dl
ROL eax, cl
end; Function LShr(Value : Cardinal; Bit : Byte):Integer; register;
asm
mov cl, dl
ROR eax, cl
end;
Pascal版本的函数
Function LShl(Value : Cardinal; Bit : Byte):Integer;
begin
Result := (Value shr (32 - Bit))or(Value shl Bit);
end;
Function LShr(Value : Cardinal; Bit : Byte):Integer;
begin
Result := (Value shl (32 - Bit))or(Value shr Bit);
end;
>> op1 >> op2 右移op1 op2位
<< op1 << op2 左移op1 op2位
>>> op1 >>> op2 右移op1 op2位 (无符号移位) 对于Delphi来说,这三个Java操作符对应Delphi的两个操作符shr和shl,
而Delphi的shr的操作数如果是定义的有符号数,那么这时它对应java的>>
即如果定义
i:integer;//i是有符号数
Delphi的 i shr 3 相当于Java的i>>3
而如果Delphi的操作数如果是无符号数,那么这时shr对应Java的>>>
即
i:byte;
i shr 2相当于i>>>2
另外:
Java中没有<<<这个东西!