- 论坛徽章:
- 0
|
本帖最后由 shouma86 于 2012-05-28 13:41 编辑
求代码高手看看这个程序,不太理解.小弟重新编辑了下。希望给位给予指导。
#include "StdAfx.h"
#include "AbisL3DecFieldCom.h"
#ifndef DEC_REVERSED_BITS
#define POS(bit)
(1 << (7 - (bit & 7)))////2的7-bit次方?
#else
#define POS(bit)
(1 << (bit & 7))/////2的bit次方?
#endif
#define SRC(x, y)
(*(((const unsigned char *) x) + (y >> 3)))
#define DST(x, y)
(*(((unsigned char *) x) + (y >> 3)))
int DecBitsToInt2(const void *Source, long SourceOffset, int Count)
{
int bitSourceOffset = (SourceOffset %(八)) ;// 以一个字节为单位,//偏移量为余数,也就是最多偏移7位
BYTE ucBitSource = * ((BYTE*)Source + (SourceOffset/(八)));//取数据,//
ucBitSource <<= (8 - bitSourceOffset - Count);//数据整体偏左移
ucBitSource >>= (8 - Count); //数据整体偏右移
return ucBitSource;
}
int DecBitsToInt(const void *Source, long SourceOffset, int Count)
{
/*~~~~~~~~~~~*/
#ifndef DEC_REVERSED_INTEGER
int i, ret = 0;
for(i = 0; i < Count; i++)
{
if((SRC(Source, SourceOffset) & POS(SourceOffset)) != 0)
{
ret |= (1 << (Count - i - 1));
}
SourceOffset++;
}
return ret;
#else
int i, ret = 0;
SourceOffset += Count - 1;
for(i = 0; i < Count; i++)
{
if((SRC(Source, SourceOffset) & POS(SourceOffset)) != 0)
{
ret |= (1 << (Count - i - 1));
}
SourceOffset--;
}
return ret;
#endif
}
void DecBitsToBits(const void *Source, long SourceOffset, const void *Destination, long DestOffset, int Length)
{
if (Length < 1)
return;
long
l;
/* Optimization: if length and offsets are byte-aligned, use memcpy */
if(!((DestOffset | SourceOffset | Length) & 7))
{
memcpy(((char *) Destination) + (DestOffset >> 3), ((const char *) Source) + (SourceOffset >> 3), Length >> 3);
return;
}
for(l = 0; l < Length; l++)
{
if((SRC(Source, SourceOffset) & POS(SourceOffset)) != 0)
{
DST(Destination, DestOffset) |= POS(DestOffset);
}
else
{
DST(Destination, DestOffset) &= ~POS(DestOffset);
}
SourceOffset++;
DestOffset++;
}
return;
} |
|