[erlang-questions] erlang and crc32

Rapsey <>
Tue Feb 9 13:14:00 CET 2010


crc(B) ->
    crc(B, 4294967295).
crc(<<F:8,Rem/binary>>,CRC) ->
    <<N:8>> = <<CRC:8>>,
    crc(Rem, element((N bxor F) + 1, ?CRC) bxor (CRC bsr 8));
crc(<<>>, LCRC) ->
    <<CRC:32/little>> = <<LCRC:32>>,
    CRC.

-define(CRC,  {16#00000000, 16#B71DC104, 16#6E3B8209, 16#D926430D,
16#DC760413, 16#6B6BC517,
                16#B24D861A, 16#0550471E, 16#B8ED0826, 16#0FF0C922,
16#D6D68A2F, 16#61CB4B2B,
                16#649B0C35, 16#D386CD31, 16#0AA08E3C, 16#BDBD4F38,
16#70DB114C, 16#C7C6D048,
                16#1EE09345, 16#A9FD5241, 16#ACAD155F, 16#1BB0D45B,
16#C2969756, 16#758B5652,
                16#C836196A, 16#7F2BD86E, 16#A60D9B63, 16#11105A67,
16#14401D79, 16#A35DDC7D,
                16#7A7B9F70, 16#CD665E74, 16#E0B62398, 16#57ABE29C,
16#8E8DA191, 16#39906095,
                16#3CC0278B, 16#8BDDE68F, 16#52FBA582, 16#E5E66486,
16#585B2BBE, 16#EF46EABA,
                16#3660A9B7, 16#817D68B3, 16#842D2FAD, 16#3330EEA9,
16#EA16ADA4, 16#5D0B6CA0,
                16#906D32D4, 16#2770F3D0, 16#FE56B0DD, 16#494B71D9,
16#4C1B36C7, 16#FB06F7C3,
                16#2220B4CE, 16#953D75CA, 16#28803AF2, 16#9F9DFBF6,
16#46BBB8FB, 16#F1A679FF,
                16#F4F63EE1, 16#43EBFFE5, 16#9ACDBCE8, 16#2DD07DEC,
16#77708634, 16#C06D4730,
                16#194B043D, 16#AE56C539, 16#AB068227, 16#1C1B4323,
16#C53D002E, 16#7220C12A,
                16#CF9D8E12, 16#78804F16, 16#A1A60C1B, 16#16BBCD1F,
16#13EB8A01, 16#A4F64B05,
                16#7DD00808, 16#CACDC90C, 16#07AB9778, 16#B0B6567C,
16#69901571, 16#DE8DD475,
                16#DBDD936B, 16#6CC0526F, 16#B5E61162, 16#02FBD066,
16#BF469F5E, 16#085B5E5A,
                16#D17D1D57, 16#6660DC53, 16#63309B4D, 16#D42D5A49,
16#0D0B1944, 16#BA16D840,
                16#97C6A5AC, 16#20DB64A8, 16#F9FD27A5, 16#4EE0E6A1,
16#4BB0A1BF, 16#FCAD60BB,
                16#258B23B6, 16#9296E2B2, 16#2F2BAD8A, 16#98366C8E,
16#41102F83, 16#F60DEE87,
                16#F35DA999, 16#4440689D, 16#9D662B90, 16#2A7BEA94,
16#E71DB4E0, 16#500075E4,
                16#892636E9, 16#3E3BF7ED, 16#3B6BB0F3, 16#8C7671F7,
16#555032FA, 16#E24DF3FE,
                16#5FF0BCC6, 16#E8ED7DC2, 16#31CB3ECF, 16#86D6FFCB,
16#8386B8D5, 16#349B79D1,
                16#EDBD3ADC, 16#5AA0FBD8, 16#EEE00C69, 16#59FDCD6D,
16#80DB8E60, 16#37C64F64,
                16#3296087A, 16#858BC97E, 16#5CAD8A73, 16#EBB04B77,
16#560D044F, 16#E110C54B,
                16#38368646, 16#8F2B4742, 16#8A7B005C, 16#3D66C158,
16#E4408255, 16#535D4351,
                16#9E3B1D25, 16#2926DC21, 16#F0009F2C, 16#471D5E28,
16#424D1936, 16#F550D832,
                16#2C769B3F, 16#9B6B5A3B, 16#26D61503, 16#91CBD407,
16#48ED970A, 16#FFF0560E,
                16#FAA01110, 16#4DBDD014, 16#949B9319, 16#2386521D,
16#0E562FF1, 16#B94BEEF5,
                16#606DADF8, 16#D7706CFC, 16#D2202BE2, 16#653DEAE6,
16#BC1BA9EB, 16#0B0668EF,
                16#B6BB27D7, 16#01A6E6D3, 16#D880A5DE, 16#6F9D64DA,
16#6ACD23C4, 16#DDD0E2C0,
                16#04F6A1CD, 16#B3EB60C9, 16#7E8D3EBD, 16#C990FFB9,
16#10B6BCB4, 16#A7AB7DB0,
                16#A2FB3AAE, 16#15E6FBAA, 16#CCC0B8A7, 16#7BDD79A3,
16#C660369B, 16#717DF79F,
                16#A85BB492, 16#1F467596, 16#1A163288, 16#AD0BF38C,
16#742DB081, 16#C3307185,
                16#99908A5D, 16#2E8D4B59, 16#F7AB0854, 16#40B6C950,
16#45E68E4E, 16#F2FB4F4A,
                16#2BDD0C47, 16#9CC0CD43, 16#217D827B, 16#9660437F,
16#4F460072, 16#F85BC176,
                16#FD0B8668, 16#4A16476C, 16#93300461, 16#242DC565,
16#E94B9B11, 16#5E565A15,
                16#87701918, 16#306DD81C, 16#353D9F02, 16#82205E06,
16#5B061D0B, 16#EC1BDC0F,
                16#51A69337, 16#E6BB5233, 16#3F9D113E, 16#8880D03A,
16#8DD09724, 16#3ACD5620,
                16#E3EB152D, 16#54F6D429, 16#7926A9C5, 16#CE3B68C1,
16#171D2BCC, 16#A000EAC8,
                16#A550ADD6, 16#124D6CD2, 16#CB6B2FDF, 16#7C76EEDB,
16#C1CBA1E3, 16#76D660E7,
                16#AFF023EA, 16#18EDE2EE, 16#1DBDA5F0, 16#AAA064F4,
16#738627F9, 16#C49BE6FD,
                16#09FDB889, 16#BEE0798D, 16#67C63A80, 16#D0DBFB84,
16#D58BBC9A, 16#62967D9E,
                16#BBB03E93, 16#0CADFF97, 16#B110B0AF, 16#060D71AB,
16#DF2B32A6, 16#6836F3A2,
                16#6D66B4BC, 16#DA7B75B8, 16#035D36B5, 16#B440F7B1,
16#00000001}).


Sergej

On Tue, Feb 9, 2010 at 10:27 AM, Max Lapshin <> wrote:

> Hi, while working with MPEG TS, I've encountered problems with crc32.
> Here is a part of PAT header:
>
> PAT = <<00,00,16#b0,16#0d,16#1c,16#18,16#d1,00,00,00,16#01,16#e0,16#42>>.
>
> VLC generates such CRC32:
>
> <<16#90,16#25,16#12,16#e2>> = <<2418348770:32>>.
>
> But erlang:crc32(PAT) = 2322700764
>
> In this article author solves the same problem:
>
> http://easyerl.blogspot.com/2007/11/nagios-beurk-nrpe-support-for-erlang.html
>
> He implements the same algorithm, as VLC does. More discussion:
> http://www.mail-archive.com/linux-dvb@linuxtv.org/msg22401.html
> There is told, that algorithm requires changes.
>
> Questions are:
> 1) are there really different flavours of crc32?
> 2) can I rearrange my data so, that erlang:crc32 or any other default
> function will work?
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>
>


More information about the erlang-questions mailing list