Beispiel #1
0
        public static byte GetLSB(ushort val, BufferDirection direction = BufferDirection.Forward, BufferEndianess endianess = BufferEndianess.LittleEndian)
        {
            switch (direction)
            {
            case BufferDirection.Forward:
                return((byte)(val & 0xFF));

            case BufferDirection.Backward:
                return((byte)((val >> 8) & 0xFF));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #2
0
        public static byte[] GetBytes(int val, BufferDirection direction = BufferDirection.Forward, BufferEndianess endianess = BufferEndianess.LittleEndian)
        {
            var ret = new byte[4];

            switch (direction)
            {
            case BufferDirection.Forward:
                ret[3] = (byte)(val & 0xFF);
                ret[2] = (byte)((val >> 8) & 0xFF);
                ret[1] = (byte)((val >> 16) & 0xFF);
                ret[0] = (byte)((val >> 24) & 0xFF);
                break;

            case BufferDirection.Backward:
                ret[0] = (byte)(val & 0xFF);
                ret[1] = (byte)((val >> 8) & 0xFF);
                ret[2] = (byte)((val >> 16) & 0xFF);
                ret[3] = (byte)((val >> 24) & 0xFF);
                break;

            default:
                throw new NotSupportedException();
            }
            return(ret);
        }
Beispiel #3
0
        public static short GetShort(byte msb, byte lsb, BufferDirection direction = BufferDirection.Forward, BufferEndianess endianess = BufferEndianess.LittleEndian)
        {
            switch (direction)
            {
            case BufferDirection.Forward:
                return((short)((msb << 8) | lsb));

            case BufferDirection.Backward:
                return((short)((lsb << 8) | msb));

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #4
0
        public static int GetInt(byte msb4, byte msb3, byte lsb2, byte lsb1, BufferDirection direction = BufferDirection.Forward, BufferEndianess endianess = BufferEndianess.LittleEndian)
        {
            switch (direction)
            {
            case BufferDirection.Forward:
                return((((((msb4 << 8) | msb3) << 8) | lsb2) << 8) | lsb1);

            case BufferDirection.Backward:
                return((((((lsb1 << 8) | lsb2) << 8) | msb3) << 8) | msb4);

            default:
                throw new NotSupportedException();
            }
        }