Need help decoding a bit of C++ code
<p>I have to convert some C++ code to C#, and I don't understand what these bits of code mean. There's a lot of bitshifting involved. I know that a Bitmap of a Signature (1BPP, I think) is passed to it. I'm not even sure what it outputs.</p>

<pre><code>#include "Sig.h"    // Signature storage definitions

//-----------------------------------------------------------------------------

// LOCAL DEFINITIONS

#define BPL (sizeof(unsigned long) * 8) // Bits per long

//-----------------------------------------------------------------------------

inline int
GetBit (
    unsigned long HUGE *map,    // Bitmap
    int     &amp;x,     // Source column
    int     &amp;y)     // Source line
{
    int     b;      // Result

    if (y &gt;= SIG_HGT) return 2;
    b = (
        (unsigned char HUGE*)
        (map + (unsigned long)y * ((SIG_WID + BPL - 1) / BPL))
    ) [ x&gt;&gt;3 ] &gt;&gt; (7-(x&amp;7)) &amp; 1;
    if (++x &gt;= SIG_WID) x = 0, y++;
    return b;
}    

//-----------------------------------------------------------------------------

// PACK SIGNATURE

void
SigPck (
    Sig_t       *sig,       // Signature record
    HGLOBAL     hDib)       // Device independent bitmap handle
{
    void        *pDib;      // Pointer to source block
    BITMAPINFO  *pDibInfo;  // Pointer to source information
    unsigned long HUGE *pDibBits;   // Pointer to source bits
    unsigned    ctbCnt;     // Colour table element count
    unsigned short  lw;     // Length of white space
    unsigned short  lb;     // Length of black space
    int     x;      // Source column
    int     y;      // Source line
    int     b;      // Current bit state
    unsigned short  m;      // Bitmap
    unsigned short  i;      // General purpose index

    // Lookup source components

    if ((pDib = GlobalLock (hDib)) == NULL)
        ErrApp ("SigPck 1");
    pDibInfo = (BITMAPINFO FAR *)pDib;
    if (pDibInfo-&gt;bmiHeader.biBitCount &gt;= 24)
        ctbCnt = 0;
    else
    ctbCnt = 1 &lt;&lt; pDibInfo-&gt;bmiHeader.biBitCount;
pDibBits = (unsigned long HUGE*)
    ((char*)pDib + sizeof(BITMAPINFOHEADER) +
        sizeof(RGBQUAD)*ctbCnt);

// Check source bitmap dimensions

if (
    pDibInfo-&gt;bmiHeader.biBitCount != 1 ||
    pDibInfo-&gt;bmiHeader.biWidth != SIG_WID ||
    pDibInfo-&gt;bmiHeader.biHeight != SIG_HGT
) ErrApp ("SigPck: Bad DIB");

// Packing process

sig-&gt;sigLen = 0;
x = 0;
y = 0;
b = GetBit (pDibBits, x, y);
while (b != 2) {

    // Check for overrun

    if (sig-&gt;sigLen &gt;= SIG_MXL)
        ErrApp ("SigPck: Overrun");

    // Calculate run lengths

    lw = 0;
    while (lw &lt; SIG_MXW &amp;&amp; b == 1) {
        lw ++ ;
        b = GetBit (pDibBits, x, y);
    }
    lb = 0;
    while (lb &lt; SIG_MXB &amp;&amp; b == 0) {
        lb ++ ;
        b = GetBit (pDibBits, x, y);
    }
    if (lw+lb &gt; SIG_BPW || b == 2) {
        sig-&gt;sigArr[ sig-&gt;sigLen++ ] = SigErl (lw, lb);
    } else {
        m = ((1 &lt;&lt; lw) - 1) &lt;&lt; lb;
        for (i = lw+lb; i &lt; SIG_BPW; i++) {
            m = (m &lt;&lt; 1) | (b &amp; 1);
            b = GetBit (pDibBits, x, y);
        }
        sig-&gt;sigArr[ sig-&gt;sigLen++ ] = SigEbm (m);
    }
}

// Release the bitmap

GlobalUnlock (hDib);
}
</code></pre>

<p>Anyone here recognize anything familiar? I can't really convert these to C# without knowing what it'll do.</p>
