background preloader

Algorithms

Facebook Twitter

Algorithms and Data Structures with Java and C++ implementations. BSD checksum. Computation of the BSD checksum[edit] Below is the relevant part of the GNU sum source code (GPL licensed). It computes a 16-bit checksum by adding up all 16-bit chars of the input data stream. In order to avoid many of the weaknesses of simply adding the data, the checksum accumulator is circular rotated to the right by one bit at each step before the new char is added. FILE *fp; /* The file handle for input data */int ch; /* Each character read. */int checksum = 0; /* The checksum mod 2^16. */ while ((ch = getc (fp)) ! Below is a sample java code that calculates an 8-bit checksum. Description of the algorithm[edit] As mentioned above, this algorithm computes a checksum by segmenting the data and adding it to an accumulator that is circular right shifted between each summation. Example: 4-bit checksum using 4-bit sized segments (big-endian:Endianness) Input: 101110001110 Loop 1: checksum: 0000 seg: 1011 a) Circular shift checksum: b) Add seg and bitmask: Loop 2: checksum: 1011 seg: 1000 Loop 3:

Forward error correction. The redundancy allows the receiver to detect a limited number of errors that may occur anywhere in the message, and often to correct these errors without retransmission. FEC gives the receiver the ability to correct errors without needing a reverse channel to request retransmission of data, but at the cost of a fixed, higher forward channel bandwidth. FEC is therefore applied in situations where retransmissions are costly or impossible, such as one-way communication links and when transmitting to multiple receivers in multicast. FEC information is usually added to mass storage devices to enable recovery of corrupted data, and is widely used in modems. FEC processing in a receiver may be applied to a digital bit stream or in the demodulation of a digitally modulated carrier. For the latter, FEC is an integral part of the initial analog-to-digital conversion in the receiver.

How it works[edit] Up to 1 bit of triplet in error, orup to 2 bits of triplet omitted (cases not shown in table). Parity bit. There are two variants of parity bits: even parity bit and odd parity bit. In the case of even parity, the number of bits whose value is 1 in a given set are counted. If that total is odd, the parity bit value is set to 1, making the total count of 1's in the set an even number.

If the count of ones in a given set of bits is already even, the parity bit's value remains 0. Cyclic redundancy check. A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.

Cyclic redundancy check

Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match. The CRC was invented by W. Wesley Peterson in 1961; the 32-bit CRC function of Ethernet and many other standards is the work of several researchers and was published during 1975.

Introduction[edit] CRCs are based on the theory of cyclic error-correcting codes. A CRC is called an n-bit CRC when its check value is n bits. IP Checksum Introduction. Short description of the Internet checksum IP checksum definition The IP checksum is the 16 bit one's complement of the one's complement sum of all 16 bit words in the header. One question many people may ask is "What is the 1's complement sum ? ". This is because all computers utilize the 2's complement representation and the 1's complement is not used. The following gives a short introduction. 2's complement fixed point integers (8-bit) Let's add two intergers: -3 + 5 = 2 FD + 05 = 01 02Discarding the carry (01) gives the correct result.

Hash

Text Searching/Scanning.