ToUInt64() public static method

public static ToUInt64 ( byte value, int startIndex ) : UInt64
value byte
startIndex int
return UInt64
Ejemplo n.º 1
0
        public UInt256(byte[] value)
        {
            if (value.Length > 32 && !(value.Length == 33 && value[32] == 0))
            {
                throw new ArgumentOutOfRangeException();
            }

            if (value.Length < 32)
            {
                value = value.Concat(new byte[32 - value.Length]);
            }

            // read LE parts in reverse order to store in BE
            var part1Bytes = new byte[8];
            var part2Bytes = new byte[8];
            var part3Bytes = new byte[8];
            var part4Bytes = new byte[8];

            Buffer.BlockCopy(value, 0, part4Bytes, 0, 8);
            Buffer.BlockCopy(value, 8, part3Bytes, 0, 8);
            Buffer.BlockCopy(value, 16, part2Bytes, 0, 8);
            Buffer.BlockCopy(value, 24, part1Bytes, 0, 8);

            // convert parts and store
            this.part1 = Bits.ToUInt64(part1Bytes);
            this.part2 = Bits.ToUInt64(part2Bytes);
            this.part3 = Bits.ToUInt64(part3Bytes);
            this.part4 = Bits.ToUInt64(part4Bytes);

            this.hashCode = this.part1.GetHashCode() ^ this.part2.GetHashCode() ^ this.part3.GetHashCode() ^ this.part4.GetHashCode();
        }
Ejemplo n.º 2
0
        private void InnerInit(byte[] buffer, int offset, out ulong[] parts, out int hashCode)
        {
            // convert parts and store
            parts   = new ulong[width];
            offset += 32;
            for (var i = 0; i < width; i++)
            {
                offset  -= 8;
                parts[i] = Bits.ToUInt64(buffer, offset);
            }


            InnerInit(out hashCode);
        }