BitSharper.Utils.ReverseBytes C# (CSharp) Method

ReverseBytes() public static method

Returns a copy of the given byte array in reverse order.
public static ReverseBytes ( byte bytes ) : byte[]
bytes byte
return byte[]
        public static byte[] ReverseBytes(byte[] bytes)
        {
            // We could use the XOR trick here but it's easier to understand if we don't. If we find this is really a
            // performance issue the matter can be revisited.
            var buf = new byte[bytes.Length];
            for (var i = 0; i < bytes.Length; i++)
                buf[i] = bytes[bytes.Length - 1 - i];
            return buf;
        }

Usage Example

Ejemplo n.º 1
0
        /// <exception cref="ProtocolException"/>
        protected override void Parse()
        {
            _version          = ReadUint32();
            _prevBlockHash    = ReadHash();
            _merkleRoot       = ReadHash();
            _time             = ReadUint32();
            _difficultyTarget = ReadUint32();
            _nonce            = ReadUint32();

            _hash = new Sha256Hash(Utils.ReverseBytes(Utils.DoubleDigest(Bytes, 0, Cursor)));

            if (Cursor == Bytes.Length)
            {
                // This message is just a header, it has no transactions.
                return;
            }

            var numTransactions = (int)ReadVarInt();

            Transactions = new List <Transaction>(numTransactions);
            for (var i = 0; i < numTransactions; i++)
            {
                var tx = new Transaction(Params, Bytes, Cursor);
                Transactions.Add(tx);
                Cursor += tx.MessageSize;
            }
        }
All Usage Examples Of BitSharper.Utils::ReverseBytes