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
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
...全文
相关推荐
Python语言程序设计教程 北理工Python课程W040203-死循环半路循环 共10页.pdf
这些知识点共同构成了Python编程的基础,对于深入理解和运用Python至关重要。通过学习这些内容,学员将能够熟练地编写Python程序,解决实际问题。
dm收集1
11。
使用GDB调试PHP代码,解决PHP代码死循环问题
本例中所提到的使用GDB调试PHP代码并解决死循环问题的实践,不仅适用于PHP语言,也适用于其他使用Zend引擎的脚本语言,如Perl、Python等。
py代码-例2-3-2 死循环
在Python编程语言中,"死循环"是指一个循环结构无法自行终止,会一直持续执行,直到手动停止或程序出现错误。这种循环通常由于循环条件始终为真或者没有正确的退出机制导致。
c语言编译器(python版)使用python语言编写的c语言编译
C语言编译器通过利用C语言的空语句(`;`)巧妙地解决了这个问题。空语句可以作为语法构造的终止符,帮助避免左递归导致的无限递归。4.


