Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
raw byte of integer
#5
I knocked another second off by condensing all the temporary variables into a one liner.
Anyone see anything else at all to do here? The unsigned macro just caps it back to 32 bits after shifting up (cpu shift would discard bits that go off the end, python grows them).
crctab is just the polynomial as a lookup table of 256 32 bit y=f(x) results.
UNSIGNED = lambda n: n & 0xffffffff    
def crc32p(b):
    crc = 0
    for c in b:                
        crc = (UNSIGNED(crc << 8) ^ (crctab[( (crc>>24) ^ c )]))
    return crc^0xFFFFFFFF  #some crc need a final xor, mine does. 
4.3 sec / M.
Reply


Messages In This Thread
raw byte of integer - by jonnin - Jul-21-2019, 03:08 PM
RE: raw byte of integer - by jonnin - Jul-21-2019, 07:31 PM
RE: raw byte of integer - by scidam - Jul-21-2019, 11:25 PM
RE: raw byte of integer - by jonnin - Jul-22-2019, 12:49 AM
RE: raw byte of integer - by jonnin - Jul-22-2019, 03:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,522 Sep-18-2020, 10:10 PM
Last Post: tienttt
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 31,655 Feb-08-2020, 06:58 PM
Last Post: karkas
  4 byte hex byte swap from binary file medievil 7 22,076 May-08-2018, 08:16 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020