actionscript 3-如何将操作脚本3转换为c#

本文关键字:转换 脚本 操作 actionscript | 更新日期: 2023-09-27 17:59:15

all。

我正在尝试使用C#解析一些二进制(AMF3)数据。

我发现了一些有用的类和函数https://code.google.com/p/cvlib/source/browse/trunk/as3/com/coursevector/amf/AMF3.as

下面有一个静态函数。

class UUIDUtils {
    private static var UPPER_DIGITS:Array = [
        '0', '1', '2', '3', '4', '5', '6', '7',
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
        ];
    public static function fromByteArray(ba:ByteArray):String {
        if (ba != null && ba.length == 16) {
            var result:String = "";
            for (var i:int = 0; i < 16; i++) {
                if (i == 4 || i == 6 || i == 8 || i == 10) result += "-";
                result += UPPER_DIGITS[(ba[i] & 0xF0) >>> 4];
                result += UPPER_DIGITS[(ba[i] & 0x0F)];
            }
            return result;
        }
        return null;
    }
}

它看起来像Java,但事实并非如此。

我想这是动作脚本3。

不管怎样,我来到这里是为了把它转换成C#。

所以我的代码如下所示。

static string[] UPPER_DIGITS = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
static string FromAMF3ByteArray(byte[] ba)
{
    if (ba != null && ba.Length == 16) {
        string result   = "";
        for (int i = 0; i < 16; i++)
        {
            if (i == 4 || i == 6 || i == 8 || i == 10)
                result += "-";
            result += UPPER_DIGITS[(ba[i] & 0xF0) >>> 4];
            result += UPPER_DIGITS[(ba[i] & 0x0F)];
        }
        return result;
    }
    return null;
}

但我在结果+=UPPER_DIGITS[(ba[I]&0xF0)>>>4]处得到语法错误;。

有人能给我一些关于>>的建议吗?

actionscript 3-如何将操作脚本3转换为c#

>>>是ActionScript中的一个逐位无符号右移运算符。当应用于无符号类型(byte、uint、ulong)时,它相当于C#中的右移运算符。请在下面找到正确的翻译:

private static string FromAMF3ByteArray(byte[] ba)
{
    if (ba != null && ba.Length == 16)
    {
        string result = "";
        for (int i = 0; i < 16; i++)
        {
            if (i == 4 || i == 6 || i == 8 || i == 10) result += "-";
            result += UPPER_DIGITS[(ba[i] & 0xF0) >> 4];
            result += UPPER_DIGITS[(ba[i] & 0x0F)];
        }
        return result;
    }
    return null;
}