working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,563 snippets matching: integer

    public by cghersi modified Jan 31, 2014  474975  5  7  0

    C#: Parse a comma separated string into a collection of numeric items

    This method can be used with any separator you need, just setting the 'separator' input
    public static List<long> ParseIntoListOfLongs(string content, char separator = ',')
    {
        List<long> ids = new List<long>();
    
        if (string.IsNullOrEmpty(content))
            return ids;
    
        string[] strIds = content.Split(separator);
        foreach (string str in strIds)
        {
            long id = -1;
            if (long.TryParse(str, out id))
            {
                if (id > 0)
                    ids.Add(id);
            }
        }
    
        return ids;
    }
    

    public by lbottaro modified Nov 6, 2012  311295  3  6  0

    Get MAC address of current interface in Python

    This python uses uuid.getnode to get current mac address as an integer. It formats the number in a standard mac address form (i.e. bytes splitted by :)
    import uuid
    print ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])
    

    public by Geometry modified Aug 6, 2016  93251  0  5  0

    Convert: Converts a signed 16-bit integer sample into a 32-bit signed integer sample.

    Converts a signed 16-bit integer sample into a 32-bit signed integer sample. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a signed 16-bit integer sample
    ///   into a 32-bit signed integer sample.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int16 from, out Int32 to)
    {
        to = (byte)(((from) >> 8) + 128);
    }

    public by Geometry modified Aug 17, 2016  89887  0  3  0

    IsInteger: Determines whether a number is an integer, given a tolerance threshold.

    Determines whether a number is an integer, given a tolerance threshold. The value to be compared. The maximum that the number can deviate from its closest integer number. True if the number if an integer, false otherwise.
    #region Comparison
    
    /// <summary>
    ///   Determines whether a number is an integer, given a tolerance threshold.
    /// </summary>
    /// 
    /// <param name="x">The value to be compared.</param>
    /// <param name="threshold">The maximum that the number can deviate from its closest integer number.</param>
    /// 
    /// <returns>True if the number if an integer, false otherwise.</returns>
    /// 
    public static bool IsInteger(this double x, double threshold)
    {
        double a = Math.Round(x);
        double b = x;
    
        if (a == b)
            return true;
    
        double limit = Math.Abs(a) * threshold;
        double delta = Math.Abs(a - b);
    
        return delta <= limit;
    }

    public by Geometry modified Sep 25, 2016  69205  0  3  0

    ToInt16: Converts a integer to a short integer.

    Converts a integer to a short integer.
    /// <summary>
            ///   Converts a integer to a short integer.
            /// </summary>
            /// 
    #if NET45
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
    #endif
            public static short[][] ToInt16(this int[][] value)
            {
                return ToInt16(value, Jagged.CreateAs<int, short>(value));
            }

    public by Geometry modified Aug 6, 2016  76034  0  5  0

    Convert: Converts a array of signed 32-bit integer samples into a array of 32-bit floating point samples.

    Converts a array of signed 32-bit integer samples into a array of 32-bit floating point samples. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a array of signed 32-bit integer samples
    ///   into a array of 32-bit floating point samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int32[] from, Int32[] to)
    {
        for (int i = 0; i < from.Length; i++)
            to[i] = (int)((double)from[i] * 0x7FFFFFFF);
    }

    public by Geometry modified Aug 6, 2016  63374  0  3  0

    Convert: Converts a matrix of unsigned 8-bit byte samples into a array of 16-bit short integer samples.

    Converts a matrix of unsigned 8-bit byte samples into a array of 16-bit short integer samples. The original sample. The resulting sample.
    #endregion
    
    
    #region From UInt8 (byte)
    
    #region From UInt8 (byte) to Int16 (short)
    /// <summary>
    ///   Converts a matrix of unsigned 8-bit byte samples
    ///   into a array of 16-bit short integer samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(byte[][] from, Int16[][] to)
    {
        for (int i = 0; i < from.Length; i++)
            for (int j = 0; j < from[0].Length; j++)
                to[i][j] = (Int16)((from[i][j] - 128) << 8);
    }

    public by Geometry modified Aug 6, 2016  47487  0  5  0

    Convert: Converts a unsigned 8-bit byte sample into a 16-bit short integer sample.

    Converts a unsigned 8-bit byte sample into a 16-bit short integer sample. The original sample. The resulting sample.
    /// <summary>
    ///   Converts a unsigned 8-bit byte sample
    ///   into a 16-bit short integer sample.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(byte from, out Int16 to)
    {
        to = (Int16)((from - 128) << 8);
    }

    public by Geometry modified Sep 25, 2016  42649  0  3  0

    ToDecimal: Converts a multidimensional integer array to a jagged decimal fixed-point array.

    Converts a multidimensional integer array to a jagged decimal fixed-point array.
    /// <summary>
            ///   Converts a multidimensional integer array to a jagged decimal fixed-point array.
            /// </summary>
            /// 
    #if NET45
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
    #endif
            public static decimal[][] ToDecimal(this int[,] value, decimal[][] result)
            {
                            for (int i = 0; i < result.Length; i++)
                    for (int j = 0; j < result[i].Length; j++)
                        result[i][j] = (Decimal)value[i, j];
                return result;
            }

    public by Geometry modified Aug 6, 2016  31150  0  5  0

    Convert: Converts a matrix of signed 16-bit integer samples into a matrix of 64-bit floating point samples.

    Converts a matrix of signed 16-bit integer samples into a matrix of 64-bit floating point samples. The original sample. The resulting sample.
    private const float const_1_div_32768_ = 1f / 32768f;
    
    #endregion
    
    #region From Int16 (short) to Single (float)
    /// <summary>
    ///   Converts a matrix of signed 16-bit integer samples
    ///   into a matrix of 64-bit floating point samples.
    /// </summary>
    /// 
    /// <param name="from">The original sample.</param>
    /// <param name="to">The resulting sample.</param>
    /// 
    public static void Convert(Int16[][] from, double[][] to)
    {
        for (int i = 0; i < from.Length; i++)
            for (int j = 0; j < from[0].Length; j++)
                to[i][j] = (double)(from[i][j] * const_1_div_32768_);
    }
    • Public Snippets
    • Channels Snippets