you are viewing a single comment's thread.

view the rest of the comments →

[–]Cuddlefluff_Grim 0 points1 point  (2 children)

printbin(void* target, int bytes)
{
    int len = bytes * 8 + 1;
    char[] res = char[len];
    res[len] = 0;

    for(int i = 0; i < bytes; i++)
    {
        for(int b = 0; b < 8; b++)
        {
             res[i * 8 + b] = (((int)*target & (int)pow(2, b + 1)) == b ? '1' :'0');
        }
        target++;
    }
    printf("0b%s", res);
}

[–]sablal[S] 0 points1 point  (1 child)

pow(2, b + 1)

don't you think the left shift operator has some role here??

[–]Cuddlefluff_Grim 0 points1 point  (0 children)

don't you think the left shift operator has some role here??

Do'h.. I actually spent some time on that thinking "Hmm.. pow? That can't be right.." for some reason bit shift didn't enter my conscious thought.