python语言的死循环问题
C语言代码
UINT16 checksum(UINT8* data, int length)
{
// CRC-CCITT CRC checksum generation
/* Importan: x86 is little endian,how about ARM? */
UINT8 i;
UINT16 crc = 0; //
while(length--)
{
for(i=0x01; i!=0; i<<=1)
{
if((crc&0x0001)!=0)
{
crc>>=1;
crc^=0x8408;
}
else
{
crc>>=1;
}
if((*data&i)!=0)
crc^=0x8408;
}
data++;
}
return crc;
}
我将上面程序转换成python,怎么陷入了死循环啊?
def fun(strData,length):
length = len(strData)
print length
j = 0x01
crc=0
for i in range(0,length):
j = 0x01
while j !=0: ####在while中陷入死循环,why?
if crc&0x001 != 0:
crc= crc>>1
crc= crc^0x8408
else:
crc = crc>>1
if ord(strData[i])& j!= 0:
crc = crc^0x8408
j = j<<1
print "run here?:" #########运行不到这个地方
i = i + 1
print "Arrive here2?"
return crc