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 mr;
    
    unsigned char invertir_byte (mr) {
    bit tempb;
    unsigned char count,temp;
    for(count=8;count;count--)
    {
       tempb=mr&0x01;
       mr>>=1;
       temp<<=1;
       temp=temp|tempb;
    }
    return (temp);
    
    }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    
    Program Size: data=12.1 xdata=0 code=64
    It's spend 175 clock cycles
    
    
    

Reply
  • #include <reg52.h>
    unsigned char mr;
    
    unsigned char invertir_byte (mr) {
    bit tempb;
    unsigned char count,temp;
    for(count=8;count;count--)
    {
       tempb=mr&0x01;
       mr>>=1;
       temp<<=1;
       temp=temp|tempb;
    }
    return (temp);
    
    }
    
    void main()
    {
    while(1)
      {
      P1=invertir_byte(0x33);
      }
    }
    
    Program Size: data=12.1 xdata=0 code=64
    It's spend 175 clock cycles
    
    
    

Children