Example #1
0
static inline void swapEndiannessFor8ByteWord(char* c)
{
  XOR_SWAP(c[0], c[7]);
  XOR_SWAP(c[1], c[6]);
  XOR_SWAP(c[2], c[5]);
  XOR_SWAP(c[3], c[4]);
}
Example #2
0
// reverse the given null-terminated string in place
void inplace_reverse(char * str)
{
  if ( str)
  {
    char * end = str + strlen( str) - 1;

    // swap the values in the two given variables
    // XXX: fails when a and b refer to same memory location
#   define XOR_SWAP(a,b) do\
    {\
      a ^= b;\
      b ^= a;\
      a ^= b;\
    } while (0)

    // walk inwards from both ends of the string, 
    // swapping until we get to the middle
    while (str < end)
    {
      XOR_SWAP(*str, *end);
      str++;
      end--;
    }
#   undef XOR_SWAP
  }
}
Example #3
0
void reverse(char * str){
  if (str){
    char * end = str + strlen(str) - 1;
#   define XOR_SWAP(a,b) do{\
      a ^= b;\
      b ^= a;\
      a ^= b;\
    } while (0)
    while (str < end){
      XOR_SWAP(*str, *end);
      str++;
      end--;
    }
#   undef XOR_SWAP
  }
}
Example #4
0
void rev(char* wurd)
{
    if ( wurd ) {
        char* end = wurd + strlen(wurd) - 1;
#define XOR_SWAP(a, b) do\
        {\
            a ^= b;\
            b ^= a;\
            a ^= b;\
        } while (0)

        while ( wurd < end ) {
            XOR_SWAP(*wurd, *end);
            wurd++;
            end--;
        }
#undef XOR_SWAP
    }
}
VALUE method_my_reverse_xor(VALUE self)
{
  VALUE dup = rb_str_dup(self);
  char* start = RSTRING_PTR(dup);
  char* end = start + RSTRING_LEN(dup) - 1;

#define XOR_SWAP(a,b) do\
  {\
    a ^= b;\
    b ^= a;\
    a ^= b;\
  } while (0)

  while(start < end)
  {
    XOR_SWAP(*start,*end);
    start++;
    end--;
  }
#undef XOR_SWAP

  return dup;
}
Example #6
0
static inline void swapEndiannessFor4ByteWord(char* c)
{
  XOR_SWAP(c[0], c[3]);
  XOR_SWAP(c[1], c[2]);
}