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

How can I exchange two bits?

The following does not work (ACC is always 0, despite out[0] is 255):

ACC0 = out[0] & 1 == 1 ? 1 : 0;
ACC1 = out[0] & 2 == 2 ? 1 : 0;
out[0] &= 0xFC;
send_string(" acc1");
send_byte(ACC);
if (ACC0)
out[0] |= 2;
if (ACC1)
out[0] |= 1;

Parents
  • Well, for starters, do you really want to do this...

    ACC0 = out[0] & 1 == 1 ? 1 : 0;
    

    ...?
    Surely the order of precedence means that you will perform the operations in this order...

    ACC0 = (255 & (1==1))?1:0
    = (255 & 1)?1:0
    = 1?1:0
    = 1

    ...or am I being daft?

    Similarly ACC1 will equal 1...

    ACC1 = (255 & (2==2))?1:0
    = (255 & 1)?1:0
    = 1?1:0
    = 1

    Don't know where you get...

    send_byte(ACC);
    

    ..your variable ACC from, you haven't said, so I can't really say why...


    ACC is always 0


    ...does this help though?

    Yours,


    Rich.

Reply
  • Well, for starters, do you really want to do this...

    ACC0 = out[0] & 1 == 1 ? 1 : 0;
    

    ...?
    Surely the order of precedence means that you will perform the operations in this order...

    ACC0 = (255 & (1==1))?1:0
    = (255 & 1)?1:0
    = 1?1:0
    = 1

    ...or am I being daft?

    Similarly ACC1 will equal 1...

    ACC1 = (255 & (2==2))?1:0
    = (255 & 1)?1:0
    = 1?1:0
    = 1

    Don't know where you get...

    send_byte(ACC);
    

    ..your variable ACC from, you haven't said, so I can't really say why...


    ACC is always 0


    ...does this help though?

    Yours,


    Rich.

Children