Category Archives: Programming Languages

[LaTeX] Using Matrix

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{bmatrix}
    x_{11}       & x_{12} & x_{13} & \dots & x_{1n} \\
    x_{21}       & x_{22} & x_{23} & \dots & x_{2n} \\
    \hdotsfor{5} \\
    x_{d1}       & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}
=
\begin{bmatrix}
    x_{11} & x_{12} & x_{13} & \dots  & x_{1n} \\
    x_{21} & x_{22} & x_{23} & \dots  & x_{2n} \\
    \vdots & \vdots & \vdots & \ddots & \vdots \\
    x_{d1} & x_{d2} & x_{d3} & \dots  & x_{dn}
\end{bmatrix}
\]
\end{document}

Reference

https://tex.stackexchange.com/questions/204621/matrix-in-latex

[C/C++] Finding trailing 0s in a binary number

int bitcount(unsigned __int64 value)
{
    if (!value)
        return SOME_DEFAULT_VALUE;

    value &= -value;
    unsigned int lsb = (unsigned) value | (unsigned) (value >> 32);
    return (int)(((((((((((unsigned) (value >> 32) != 0) * 2)
            + ((lsb & 0xffff0000) != 0)) * 2)
            + ((lsb & 0xff00ff00) != 0)) * 2)
            + ((lsb & 0xf0f0f0f0) != 0)) * 2)
            + ((lsb & 0xcccccccc) != 0)) * 2)
            + ((lsb & 0xaaaaaaaa) != 0);
}
int bitcount(unsigned char x)
{
    int b;
    for(b=0; b<7 && !(x&1); x>>=1) b++;
    
    return b;
}

Reference

https://stackoverflow.com/questions/7812044/finding-trailing-0s-in-a-binary-number

[C/C++] Dynamically allocating 2D array in C

main: malloc.c:2405: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize – 1)) == 0)’ failed.
This most likely means that there is a mistake regarding usage of “sizeof”

Reference

Various methods to allocate 2D array: https://www.geeksforgeeks.org/dynamically-allocate-2d-array-c/
Common mistake: https://stackoverflow.com/questions/46803671/sysmalloc-assertion