BitSharp.Common.Bits.ToUInt64 C# (CSharp) Method

ToUInt64() public static method

public static ToUInt64 ( byte value, int startIndex ) : UInt64
value byte
startIndex int
return UInt64
        public static UInt64 ToUInt64(byte[] value, int startIndex = 0)
        {
            return BitConverter.ToUInt64(Order(value), startIndex);
        }

Usage Example

Example #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();
        }
All Usage Examples Of BitSharp.Common.Bits::ToUInt64