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

inverter byte

elegante inversion.


/*------------------------------------------------------------------------------

                                        INVERSION DE BYTE 8 BIT, LSB ->  MSB

------------------------------------------------------------------------------*/
unsigned char mr;

unsigned char invertir_byte (mr) {

  mr = (mr & 0x0F) << 4 | (mr & 0xF0) >> 4;
  mr = (mr & 0x33) << 2 | (mr & 0xCC) >> 2;
  mr = (mr & 0x55) << 1 | (mr & 0xAA) >> 1;

return (mr);

}


Parents
  • There is one more approach. If there are two 8-bit GPIO ports to spare, one could implement byte inversion by wiring the ports appropriately. One would then write a byte to one port and read the inverted value from the other.
    On low pin count MCUs, the chip manufacturers could even do the wiring internally for ports that are not pinned out. Go on, use the idea, I'm not planning to patent it :-)

Reply
  • There is one more approach. If there are two 8-bit GPIO ports to spare, one could implement byte inversion by wiring the ports appropriately. One would then write a byte to one port and read the inverted value from the other.
    On low pin count MCUs, the chip manufacturers could even do the wiring internally for ports that are not pinned out. Go on, use the idea, I'm not planning to patent it :-)

Children