This method decodes data in string for short. - CSharp System

CSharp examples for System:Byte

Description

This method decodes data in string for short.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  w w  .ja  va  2s  .c  om*/

public class Main{
        /// <summary>
        /// This method decodes data in string for short.
        /// </summary>
        /// <param name="v">Encoded data.</param>
        /// <returns>Decoded data.</returns>
        public static short DecodeInt16(string v)
        {
            if ((v[0] | v[1]) < 0)
            {
                return -1;
            }
            return (short)((v[0] << 8) + v[1]);
        }
        /// <summary>
        /// Decodes the Encoded short data.
        /// </summary>
        /// <param name="v">Encoded data.</param>
        /// <returns>Decoded data.</returns>
        public static int DecodeInt16(byte[] v)
        {
            if ((v[0] | v[1]) < 0)
            {
                return -1;
            }
            return ((v[0] << 8) + v[1]);
        }
}

Related Tutorials