Пример #1
0
        // ----------------------- BigEndianBytesToShort -------------------------
        public static short BigEndianBytesToShort(this byte[] Bytes, int Start)
        {
            IntParts ip = new IntParts();

            ip.byte1 = Bytes[Start];
            ip.byte0 = Bytes[Start + 1];
            return(ip.ShortValue);
        }
Пример #2
0
        public static IntParts LoadBigEndianShort(byte[] Buf, int Ix)
        {
            IntParts ip = new IntParts();

            ip.byte1 = Buf[Ix];
            ip.byte0 = Buf[Ix + 1];
            return(ip);
        }
Пример #3
0
        // -------------------- ShortToBigEndianBytes ------------------------------
        public static byte[] ShortToBigEndianBytes(short InValue)
        {
            IntParts ip = new IntParts(InValue);

            byte[] beBytes = new byte[2];
            beBytes[1] = ip.byte0;
            beBytes[0] = ip.byte1;
            return(beBytes);
        }
Пример #4
0
        public static int BigEndianBytesToInt(this byte[] Bytes, int Start)
        {
            IntParts ip = new IntParts();

            ip.byte3 = Bytes[Start];
            ip.byte2 = Bytes[Start + 1];
            ip.byte1 = Bytes[Start + 2];
            ip.byte0 = Bytes[Start + 3];
            return(ip.IntValue);
        }
Пример #5
0
        /// <summary>
        /// return the short value as a big endian short stored in byte[] array.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static byte[] ToBigEndianShort(short Value)
        {
            IntParts ip = new IntParts();

            ip.ShortValue = Value;
            byte[] buf = new byte[2];
            buf[0] = ip.byte1;
            buf[1] = ip.byte0;
            return(buf);
        }
Пример #6
0
        public short GetBigEndianShort()
        {
            if (Index + 1 >= this.DataLgth)
            {
                throw new Exception("no more bytes to read from array");
            }
            var ip = IntParts.LoadBigEndianShort(this.Bytes, this.Index);

            this.Index += 2;
            return(ip.ShortValue);
        }
Пример #7
0
        // -------------------- IntToBigEndianBytes ------------------------------
        public static byte[] IntToBigEndianBytes(int InValue)
        {
            IntParts ip = new IntParts(InValue);

            byte[] beBytes = new byte[4];
            beBytes[0] = ip.byte3;
            beBytes[1] = ip.byte2;
            beBytes[2] = ip.byte1;
            beBytes[3] = ip.byte0;
            return(beBytes);
        }
Пример #8
0
        public int PeekBigEndianInt(int Offset)
        {
            var ix = this.Index + Offset;

            if (ix + 3 >= this.DataLgth)
            {
                throw new Exception("no more bytes to read from array");
            }
            var ip = IntParts.LoadBigEndianInt(this.Bytes, ix);

            return(ip.IntValue);
        }
Пример #9
0
        public void AppendBigEndianShort(short Value)
        {
            var ip = IntParts.ToBigEndianShort(Value);

            Append(ip);
        }