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--;
}
}
}
全站熱搜