了解此 delphi 方法并将其转换为 C#
Understanding this delphi method and converting it to C#
任何人都可以向我解释这段 delphi 代码的作用吗?
我知道它正在移动一些位,但我不明白目的..
function PKV_GetKeyByte(const Seed : Int64; a, b, c : Byte) : Byte;
begin
a := a mod 25;
b := b mod 3;
if a mod 2 = 0 then
result := ((Seed shr a) and [=11=]0000FF) xor ((Seed shr b) or c)
else
result := ((Seed shr a) and [=11=]0000FF) xor ((Seed shr b) and c);
end;
我如何将其转换为 C#?
这是我目前得到的:
private byte PKV_GetKeyByte(Int64 seed, byte a, byte b, byte c)
{
byte result;
int aVal = a % 25;
int bVal = b % 3;
//IF-IS-MISSING
if(a % 2 == 0)
{
}
else
{
}
return result;
}
我相信(未经测试)您想要类似...
result := ((Seed shr a) and [=10=]0000FF) xor ((Seed shr b) or c))
前往
result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) | c));
和
result := ((Seed shr a) and [=12=]0000FF) xor ((Seed shr b) and c));
前往
result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) & c));
任何人都可以向我解释这段 delphi 代码的作用吗?
我知道它正在移动一些位,但我不明白目的..
function PKV_GetKeyByte(const Seed : Int64; a, b, c : Byte) : Byte;
begin
a := a mod 25;
b := b mod 3;
if a mod 2 = 0 then
result := ((Seed shr a) and [=11=]0000FF) xor ((Seed shr b) or c)
else
result := ((Seed shr a) and [=11=]0000FF) xor ((Seed shr b) and c);
end;
我如何将其转换为 C#?
这是我目前得到的:
private byte PKV_GetKeyByte(Int64 seed, byte a, byte b, byte c)
{
byte result;
int aVal = a % 25;
int bVal = b % 3;
//IF-IS-MISSING
if(a % 2 == 0)
{
}
else
{
}
return result;
}
我相信(未经测试)您想要类似...
result := ((Seed shr a) and [=10=]0000FF) xor ((Seed shr b) or c))
前往
result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) | c));
和
result := ((Seed shr a) and [=12=]0000FF) xor ((Seed shr b) and c));
前往
result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) & c));