How to resolve the algorithm CRC-32 step by step in the M2000 Interpreter programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm CRC-32 step by step in the M2000 Interpreter programming language
Table of Contents
Problem Statement
Demonstrate a method of deriving the Cyclic Redundancy Check from within the language.
The result should be in accordance with ISO 3309, ITU-T V.42, Gzip and PNG. Algorithms are described on Computation of CRC in Wikipedia. This variant of CRC-32 uses LSB-first order, sets the initial CRC to FFFFFFFF16, and complements the final CRC. For the purpose of this task, generate a CRC-32 checksum for the ASCII encoded string:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm CRC-32 step by step in the M2000 Interpreter programming language
Source code in the m2000 programming language
Module CheckIt {
Function PrepareTable {
Dim Base 0, table(256)
For i = 0 To 255 {
k = i
For j = 0 To 7 {
If binary.and(k,1)=1 Then {
k =binary.Xor(binary.shift(k, -1) , 0xEDB88320)
} Else k=binary.shift(k, -1)
}
table(i) = k
}
=table()
}
crctable=PrepareTable()
crc32= lambda crctable (buf$) -> {
crc =0xFFFFFFFF
For i = 0 To Len(buf$) -1
crc = binary.xor(binary.shift(crc, -8), array(crctable, binary.xor(binary.and(crc, 0xff), asc(mid$(buf$, i+1, 1)))))
Next i
=0xFFFFFFFF-crc
}
Print crc32("The quick brown fox jumps over the lazy dog")=0x414fa339
}
CheckIt
Module CheckApi {
Declare CRC32 LIB "ntdll.RtlComputeCrc32" {Long Zero, a$, long s}
a$=Str$("The quick brown fox jumps over the lazy dog")
l=len(a$)*2
Hex Uint(CRC32(0,a$,l))
}
CheckApi
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Clojure programming language
You may also check:How to resolve the algorithm Range consolidation step by step in the Rust programming language
You may also check:How to resolve the algorithm System time step by step in the DBL programming language
You may also check:How to resolve the algorithm Draw a cuboid step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the JavaScript programming language