c# - 理解这个delphi方法并将其转换为C#

标签 c# delphi bit-shift

任何人都可以向我解释一下这个 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 $000000FF) xor ((Seed shr b) or c)
        else
            result := ((Seed shr a) and $000000FF) 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 $000000FF) xor ((Seed shr b) or c))

result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) | c));

result := ((Seed shr a) and $000000FF) xor ((Seed shr b) and c));

result = System.Convert.ToByte((Seed >> a) & 0x000000FF) ^ ((Seed >> b) & c));

关于c# - 理解这个delphi方法并将其转换为C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48419899/

相关文章:

assembly - 使用 %cl 左移

c# - .NET 4.5 中是否已弃用 Contexts.Context.Parameters?

c# - 异步线程未发布

delphi - 在 TDateTimePicker On 下拉菜单中设置日期

delphi - 如何在TBitmap上透明地绘制TBitmap32?

c - 逆时针旋转字节数组

c# - 如何处理 .net MVC Core 中的动态错误页面?

c# - Silverlight 5 - 调试 npctrl.dll 崩溃

macos - 使用 beginActivityWithOptions 禁用 App Nap

c++ - C++ 中从 24 位到 32 位的签名扩展