What are these values representative of in C bitwise operations?
        Posted  
        
            by ajax81
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ajax81
        
        
        
        Published on 2010-04-17T23:30:30Z
        Indexed on 
            2010/04/17
            23:33 UTC
        
        
        Read the original article
        Hit count: 270
        
Hi All,
I'm trying to reverse the order of bits in C (homework question, subject: bitwise operators). I found this solution, but I'm a little confused by the hex values (?) used -- 0x01 and 0x80.
  unsigned char reverse(unsigned char c) {
     int shift;
     unsigned char result = 0;
     for (shift = 0; shift < CHAR_BITS; shift++) {
        if (c & (0x01 << shift))
        result |= (0x80 >> shift);
     }
     return result;
  }
The book I'm working out of hasn't discussed these kinds of values, so I'm not really sure what to make of them. Can somebody shed some light on this solution? Thank you!
© Stack Overflow or respective owner