close

以byte為單位,把記憶體的內容倒過來排

void memRev_fun(void* memBuf, int byteLength)
{
  int front=0, rear;
  unsigned char tmp;

  rear = byteLength-1; //array index start from 0
  if(byteLength%2 != 0)
  {
  while(front+1 != rear-1) //odd
  {
  tmp = *(((unsigned char*)memBuf)+front);
  *(((unsigned char*)memBuf)+front) = *(((unsigned char*)memBuf)+rear);
  *(((unsigned char*)memBuf)+rear) = tmp;
  front++;
  rear--;
  }
  }
  else
  {
  while(front < rear) //even
  {
  tmp = *(((unsigned char*)memBuf)+front);
  *(((unsigned char*)memBuf)+front) = *(((unsigned char*)memBuf)+rear);
  *(((unsigned char*)memBuf)+rear) = tmp;
  front++;
  rear--;
  }
  }
}


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 lver76 的頭像
    lver76

    Iver's Blog

    lver76 發表在 痞客邦 留言(0) 人氣()