How to resolve the algorithm CRC-32 step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm CRC-32 step by step in the Wren 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 Wren programming language
Source code in the wren programming language
import "./fmt" for Conv
class CRC32 {
static init() {
__table = List.filled(256, 0)
for (i in 0..255) {
var word = i
for (j in 0..7) {
if (word&1 == 1) {
word = (word >> 1) ^ 0xedb88320
} else {
word = word >> 1
}
}
__table[i] = word
}
}
static compute(s) {
var crc = ~0
var le = s.bytes.count
for (i in 0...le) {
var crb = crc & 0xff
crc = __table[crb^s[i].bytes[0]] ^ (crc >> 8)
}
return ~crc
}
}
CRC32.init()
var crc = CRC32.compute("The quick brown fox jumps over the lazy dog")
System.print(Conv.hex(crc))
You may also check:How to resolve the algorithm Day of the week step by step in the Lingo programming language
You may also check:How to resolve the algorithm Pointers and references step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Ring programming language
You may also check:How to resolve the algorithm Metronome step by step in the J programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the D programming language