def long2bin(size, value, endian, classic_mode=False):
 text = ''
 assert (endian in (LITTLE_ENDIAN, BIG_ENDIAN))
 assert (0 <= value)
 for index in xrange(size):
  if ((value & 1) == 1):
   text += '1'
  else:
   text += '0'
  value >>= 1
 if (endian is LITTLE_ENDIAN):
  text = text[::(-1)]
 result = ''
 while (len(text) != 0):
  if (len(result) != 0):
   result += ' '
  if classic_mode:
   result += text[7::(-1)]
  else:
   result += text[:8]
  text = text[8:]
 return result

def long2bin ( size , value , endian , classic_mode = False ) : text = '' assert ( endian in ( LITTLE_ENDIAN , BIG_ENDIAN ) ) assert ( 0 <= value ) for index in xrange ( size ) : if ( ( value & 1 ) == 1 ) : text += '1' else : text += '0' value >>= 1 if ( endian is LITTLE_ENDIAN ) : text = text [ : : ( - 1 ) ] result = '' while ( len ( text ) != 0 ) : if ( len ( result ) != 0 ) : result += ' ' if classic_mode : result += text [ 7 : : ( - 1 ) ] else : result += text [ : 8 ] text = text [ 8 : ] return result
convert a number into bits : - size: size in bits of the number - value: positive number - endian: big_endian or little_endian - classic_mode : reverse each packet of 8 bits .