Decode function for big endian

Issue #13 closed
WorkerH created an issue
unsigned int srcBit = startBit;
unsigned int dstBit = bitSize - 1;
for (unsigned int i = 0; i < bitSize; ++i) {
    /* copy bit */
    if (data[srcBit / 8] & (1 << (srcBit % 8))) {
        retVal |= (1ULL << dstBit);
    }

    /* next position */
    if ((srcBit % 8) == 0) {
        srcBit += 15;
    } else {
        --srcBit;
    }
    --dstBit;
}

Does not follow this schema: https://doc.micrium.com/download/attachments/15707574/Frame%20Layout%20big%20endian%20format.png?version=1&modificationDate=1413400833000&api=v2

This should be correct:

unsigned int srcBit = startBit;
unsigned int dstBit = 0;
for (unsigned int i = 0; i < bitSize; ++i)
{
    if (data[srcBit / 8] & (1 << (srcBit % 8)))
    {
        retVal |= (1ULL << dstBit);
    }
    if ((srcBit % 8) == 7)
    {
        srcBit -= 15;
    }
    else
    {
        ++srcBit;
    }
    ++dstBit;
}

My propasal in #10 also should have fixed this issue.

Comments (6)

  1. Log in to comment