2 wcvrtyu wcvrtyu 于 2014.04.14 18:02 提问

各位大神求解,小弟跪求解,代码问题如下

virtual public byte[] Decode (string data) {
var outStream = new List ();

        int length = data.Length;
        while (length > 0) {
            if (!this.Ignore (data[length - 1])) break;
            length--;
        }

        int i = 0;
        int finish = length - 8;
        for (i = this.NextI (data, i, finish); i < finish; i = this.NextI (data, i, finish)) {
            byte b1 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b2 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b3 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b4 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b5 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b6 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b7 = dTable[data[i++]];
            i = this.NextI (data, i, finish);
            byte b8 = dTable[data[i++]];

            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            outStream.Add ((byte)((b2 << 6) | (b3 << 1) | (b4 >> 4)));
            outStream.Add ((byte)((b4 << 4) | (b5 >> 1)));
            outStream.Add ((byte)((b5 << 7) | (b6 << 2) | (b7 >> 3)));
            outStream.Add ((byte)((b7 << 5) | b8));
        }
        this.DecodeLastBlock (outStream,
            data[length - 8], data[length - 7], data[length - 6], data[length - 5],
            data[length - 4], data[length - 3], data[length - 2], data[length - 1]);

        return outStream.ToArray ();
    }

    virtual protected int DecodeLastBlock (ICollection<byte> outStream, char c1, char c2, char c3, char c4, char c5, char c6, char c7, char c8) {
        if (c3 == padding) {
            byte b1 = dTable[c1];
            byte b2 = dTable[c2];
            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            return 1;
        }

        if (c5 == padding) {
            byte b1 = dTable[c1];
            byte b2 = dTable[c2];
            byte b3 = dTable[c3];
            byte b4 = dTable[c4];
            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            outStream.Add ((byte)((b2 << 6) | (b3 << 1) | (b4 >> 4)));
            return 2;
        }

        if (c6 == padding) {
            byte b1 = dTable[c1];
            byte b2 = dTable[c2];
            byte b3 = dTable[c3];
            byte b4 = dTable[c4];
            byte b5 = dTable[c5];

            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            outStream.Add ((byte)((b2 << 6) | (b3 << 1) | (b4 >> 4)));
            outStream.Add ((byte)((b4 << 4) | (b5 >> 1)));
            return 3;
        }

        if (c8 == padding) {
            byte b1 = dTable[c1];
            byte b2 = dTable[c2];
            byte b3 = dTable[c3];
            byte b4 = dTable[c4];
            byte b5 = dTable[c5];
            byte b6 = dTable[c6];
            byte b7 = dTable[c7];

            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            outStream.Add ((byte)((b2 << 6) | (b3 << 1) | (b4 >> 4)));
            outStream.Add ((byte)((b4 << 4) | (b5 >> 1)));
            outStream.Add ((byte)((b5 << 7) | (b6 << 2) | (b7 >> 3)));
            return 4;
        }

        else {
            byte b1 = dTable[c1];
            byte b2 = dTable[c2];
            byte b3 = dTable[c3];
            byte b4 = dTable[c4];
            byte b5 = dTable[c5];
            byte b6 = dTable[c6];
            byte b7 = dTable[c7];
            byte b8 = dTable[c8];
            outStream.Add ((byte)((b1 << 3) | (b2 >> 2)));
            outStream.Add ((byte)((b2 << 6) | (b3 << 1) | (b4 >> 4)));
            outStream.Add ((byte)((b4 << 4) | (b5 >> 1)));
            outStream.Add ((byte)((b5 << 7) | (b6 << 2) | (b7 >> 3)));
            outStream.Add ((byte)((b7 << 5) | b8));
            return 5;
        }
    }

    protected int NextI (string data, int i, int finish) {
        while ((i < finish) && this.Ignore (data[i])) i++;

        return i;
    }

    protected bool Ignore (char c) {
        return (c == '\n') || (c == '\r') || (c == '\t') || (c == ' ') || (c == '-');
    }

    protected void InitialiseDecodingTable () {
        for (int i = 0; i < eTable.Length; i++) {
            dTable[eTable[i]] = (byte)i;
        }
    }

小弟新晋码农,不是很懂flash的as语言,请问这段c#代码中(byte)i如何在as3.0中实现,还有在as3.0中如何用byte数据类型,我查了很多资料,但是还是不会,例如byte b1,求大神用as3.0帮我编写一个byte类。其中dTable是ByteArray。,小弟在此跪谢。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!