Convert binary unsigned vector to dec list

Posted by Juan on Stack Overflow See other posts from Stack Overflow or by Juan
Published on 2012-09-10T03:34:08Z Indexed on 2012/09/10 3:37 UTC
Read the original article Hit count: 111

Filed under:

This code convert a unsigned long vector variable cR1 to NB_ERRORS numbers (in 'a' variable I print these numbers).

for (l = 0; l < NB_ERRORS; ++l) {
    k = (l * EXT_DEGREE) / BIT_SIZE_OF_LONG;
    j = (l * EXT_DEGREE) % BIT_SIZE_OF_LONG;

    a = cR1[k] >> j;
    if(j + EXT_DEGREE > BIT_SIZE_OF_LONG)
        a ^= cR1[k + 1] << (BIT_SIZE_OF_LONG - j);
    a &= ((1 << EXT_DEGREE) - 1);
    printf("\na=%d\n",a);
}

For example I am have a cR1 with two elements that follow: 0,0,1,1,0,1,0,0,0,0,1,0,0,1,1,1,1,1,0,0,1,1,1,1,0,0,0,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,1,0,0,1,0,0,1,0,1,0,1,1,1,0,1,0,0,1,1,1,1,0, executing that code I get (44), (228, (243), (24), (77), (39), (117), (121). This code convert from right to left, I want modify to convert from right to left, Where I will be able to modify this?

pdta: In the example case EXT_DEGREE = 8, BIT_SIZE_OF_LONG = 32

© Stack Overflow or respective owner

Related posts about c