This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Generalized approach for getting bits of varaibles declared As BDATA

Hello all,

I have been pondering upon getting each bit of a variable (e.g. declared as char) using a for loop

char bdata Char1;


bit y;
for(x=0; x<7; x++)
y = Char1^x;

My question is : Is it possible?

Parents
  • If you are trying to make y equal to bits 0 through to 7 in turn you could do this:

    unsigned char x;
    unsigned char char1;
    bit y;

    for(x=0;x<8;x++)
    {
    y=(char1 >> x) & 0x01;
    }

    There is no particular advantage I can think of for using a bdata variable in this situation.

    Stefan

Reply
  • If you are trying to make y equal to bits 0 through to 7 in turn you could do this:

    unsigned char x;
    unsigned char char1;
    bit y;

    for(x=0;x<8;x++)
    {
    y=(char1 >> x) & 0x01;
    }

    There is no particular advantage I can think of for using a bdata variable in this situation.

    Stefan

Children