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;
Well, there's the straightforward way:
bit temp; // save bit 0 temp = out[0] & 1; // bit 0 = bit 1 out[0] &= ~1; out[0] |= (out[0] & 2) ? 1 : 0; // bit 1 = temp out[0] &= ~2; out[0] |= temp ? 2 : 0;
bit tempBit; // temporary swap area bdata temp; sbit temp0 = temp^0; sbit temp1 = temp^1; temp = out[0]; tempBit = temp0; temp0 = temp1; temp1 = tempBit; out[0] = temp;
temp0 = temp0 ^ temp1; temp1 = temp0 ^ temp1; temp0 = temp0 ^ temp1;
Thank you, I've solved it this way: temp1 = out[0] & 0xFC; switch (out[0] & 3) { case 1: out[0] = temp1 | 2; break; case 2: out[0] = temp1 | 1; };