Bio.IO.BAM.BAMFormatter.GetOptionalFieldIntValueSize C# (CSharp) Method

GetOptionalFieldIntValueSize() private static method

Returns, 1 if the int value can be held in an unsinged byte. -1 if the int value can be held in a singed byte. 2 if the int value can be held in an unint16 (ushort). -2 if the int value can be held in an int16 (short). 4 if the int value can be held in an uint32. -4 if the int value can be held in an int32. 0 if the specified value can't parsed by an uint.
private static GetOptionalFieldIntValueSize ( string value ) : int
value string String representing int value.
return int
        private static int GetOptionalFieldIntValueSize(string value)
        {
            uint positiveValue;
            int negativeValue;
            if (!uint.TryParse(value, out positiveValue))
            {
                if (!int.TryParse(value, out negativeValue))
                {
                    return 0;
                }

                if (sbyte.MinValue <= negativeValue)
                {
                    return -1;
                }

                if (short.MinValue <= negativeValue)
                {
                    return -2;
                }

                return -4;
            }

            if (byte.MaxValue >= positiveValue)
            {
                return 1;
            }

            if (ushort.MaxValue >= positiveValue)
            {
                return 2;
            }

            return 4;
        }