BerLib.BerEncoding.DecodeInteger C# (CSharp) Method

DecodeInteger() public static method

public static DecodeInteger ( IBerInput input, int length ) : int
input IBerInput
length int
return int
        public static int DecodeInteger(IBerInput input, int length)
        {
            int value = 0;
             int readByte;

             for(uint byteCount = 0; byteCount < length; byteCount++)
             {
            readByte = input.ReadByte();

            if(byteCount == 0 && (readByte & 0x80) != 0)
               readByte -= 0x100;

            value = (value << 8) | readByte;
             }

             return value;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Decodes the value of the current TLV a 32bit integer.
        /// Throws an exception in case of a format mismatch.
        /// </summary>
        /// <returns>The integer value of the current TLV.</returns>
        public int GetInteger()
        {
            if (IsContainer || Length == 0 || Value == null)
            {
                ThrowError(202, "Invalid Integer encoding");
            }

            Debug.Assert(Value != null || Length == 0);
            Debug.Assert(Type == BerType.Integer || BerType.IsApplicationDefined(Type));

            var input = new BerMemoryInput(Value);

            return(BerEncoding.DecodeInteger(input, Length));
        }
All Usage Examples Of BerLib.BerEncoding::DecodeInteger