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
  • #include <reg52.h>
    unsigned char code  tab[16]={0x00,0x08,0x04,0x0c,0x02,0x0a,0x06,0x0e,
                                 0x01,0x09,0x05,0x0d,0x03,0x0b,0x07,0x0f};
    unsigned char invertir_byte (unsigned char dat)
     {
        dat = tab[(dat & 0xf0)>>4] | (tab[dat & 0x0f]<<4);
        return dat;
     }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    


    //cost 26 machine cycle
    //Program Size: data=9.0 xdata=0 code=63

Reply
  • #include <reg52.h>
    unsigned char code  tab[16]={0x00,0x08,0x04,0x0c,0x02,0x0a,0x06,0x0e,
                                 0x01,0x09,0x05,0x0d,0x03,0x0b,0x07,0x0f};
    unsigned char invertir_byte (unsigned char dat)
     {
        dat = tab[(dat & 0xf0)>>4] | (tab[dat & 0x0f]<<4);
        return dat;
     }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    


    //cost 26 machine cycle
    //Program Size: data=9.0 xdata=0 code=63

Children