Exemple #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);
        }
        public static IntParts LoadBigEndianShort(byte[] Buf, int Ix)
        {
            IntParts ip = new IntParts();

            ip.byte1 = Buf[Ix];
            ip.byte0 = Buf[Ix + 1];
            return(ip);
        }
Exemple #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);
        }
Exemple #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);
        }
        /// <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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #9
0
        public void AppendBigEndianShort(short Value)
        {
            var ip = IntParts.ToBigEndianShort(Value);

            Append(ip);
        }