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 invertir_byte (unsigned char val)
     {
    unsigned char  dat_b ,i;
     dat_b=0x00;
     for(i=0;i<=7;i++)
        {
        dat_b=dat_b|((val>>i)&0x01);
        if(i==7)break;
            dat_b=dat_b<<1;
        }
       val=dat_b;
    return(val);
     }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    



    287 cycle

    Program Size: data=9.0 xdata=0 code=57

Reply
  • #include <reg52.h>
    unsigned char invertir_byte (unsigned char val)
     {
    unsigned char  dat_b ,i;
     dat_b=0x00;
     for(i=0;i<=7;i++)
        {
        dat_b=dat_b|((val>>i)&0x01);
        if(i==7)break;
            dat_b=dat_b<<1;
        }
       val=dat_b;
    return(val);
     }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    



    287 cycle

    Program Size: data=9.0 xdata=0 code=57

Children
No data