System.BitConverter.ToInt64 C# (CSharp) Метод

ToInt64() публичный статический метод

public static ToInt64 ( byte value, int startIndex ) : long
value byte
startIndex int
Результат long
        public static unsafe long ToInt64 (byte[] value, int startIndex) {
            if( value == null)  {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
            }
        
            if ((uint) startIndex >= value.Length) {
                ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index);
            }
        
            if (startIndex > value.Length -8) {
                ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall);
            }
        
            fixed( byte * pbyte = &value[startIndex]) {
                if( startIndex % 8 == 0) { // data is aligned 
                    return *((long *) pbyte);
                }
                else {
                    if( IsLittleEndian) { 
                        int i1 = (*pbyte) | (*(pbyte + 1) << 8)  | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24);                        
                        int i2  = (*(pbyte+4)) | (*(pbyte + 5) << 8)  | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24);
                        return (uint)i1 | ((long)i2 << 32);
                    }
                    else {
                        int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16)  | (*(pbyte + 2) << 8) | (*(pbyte + 3));                        
                        int i2  = (*(pbyte+4) << 24) | (*(pbyte + 5) << 16)  | (*(pbyte + 6) << 8) | (*(pbyte + 7));
                        return (uint)i2 | ((long)i1 << 32);
                    }
                }
            }        
        }
      

Usage Example

Пример #1
0
        public BTreePage(byte[] pageData)
        {
            _byteIterator = 0;



            Records = new List <NodeRecord> {
                Capacity = (int)Static.MemMax
            };
            Childrens = new List <long> {
                Capacity = (int)Static.ChilMax
            };

            ParentIndex     = BC.ToInt64(pageData, _byteIterator);
            _byteIterator  += sizeof(long);
            SelfIndex       = BC.ToInt64(pageData, _byteIterator);
            _byteIterator  += sizeof(long);
            _presentRecords = BC.ToInt64(pageData, _byteIterator);
            _byteIterator  += sizeof(long);
            IsLeaf          = BC.ToBoolean(pageData, _byteIterator);
            _byteIterator  += sizeof(bool);

            for (var i = 0; i < _presentRecords; i++)
            {
                var key = BC.ToInt64(pageData, _byteIterator);
                _byteIterator += sizeof(long);
                var pageIndex = BC.ToInt64(pageData, _byteIterator);
                _byteIterator += sizeof(long);

                Records.Add(new NodeRecord(key, pageIndex));
            }
            if (!IsLeaf)
            {
                for (var i = 0; i < _presentRecords + 1; i++)
                {
                    Childrens.Add(BC.ToInt64(pageData, _byteIterator));
                    _byteIterator += sizeof(long);
                }
            }
        }
All Usage Examples Of System.BitConverter::ToInt64