Esempio n. 1
0
        /// <summary>
        /// 把8字节转为无符号长整型
        /// </summary>
        /// <param name="bs"></param>
        /// <returns></returns>
        public static Int16 BytesToInt16(byte[] bs)
        {
            I16Bs lbs = new I16Bs();

            lbs.bvalue = new BS2();

            for (int i = 0; i < bs.Length; i++)
            {
                switch (i)
                {
                case 0: { lbs.bvalue.b1 = bs[i]; break; }

                case 1: { lbs.bvalue.b2 = bs[i]; break; }
                }
            }

            return(lbs.i16value);
        }
Esempio n. 2
0
        /// <summary>
        /// 把16整型转为字节
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public static byte[] Int16ToBytes(Int16 v)
        {
            I16Bs lbs = new I16Bs();

            lbs.i16value = v;
            byte[] bs = new byte[2];
            for (int i = 0; i < bs.Length; i++)
            {
                switch (i)
                {
                case 0: { bs[i] = lbs.bvalue.b1; break; }

                case 1: { bs[i] = lbs.bvalue.b2; break; }
                }
            }

            return(bs);
        }