When we used to store some data on a magnetic surface. then there might be a chance to occur errors due to bad spots on the surface. errors may also be caused by some electrical issues while we transfer the data between units. thus for solving this problem we use error-detecting codes.

What is Error Detecting Codes - parity bit

It is necessary to have some methods to detect such kinds of errors while transferring the data. because errors can change our data and can transfer the wrong information to the target user. so the main principle that is used to detecting errors in coded data is to add some extra bits in the code of each character of information to aid the error detection.

The common method is that we can append a bit called parity check bit to each information code. and this parity bit is appended to the 7 bits of the code of each character. so that the total number of 1s in the character code is even.

So we have two bits 0 and 1 for the machine code. and if the total number of ones (1) is even in the character code then we append the 0 to the end of the character code. and if the total numbers of ones (1) are odd then we can add 1 and the end of the character bit code.

For example, the ASCII value of the letter E is 1000101 that is 7 bits of character E. so here we can see that the total number of 1 in the bit code of 7 is 3 and that is odd. so we need to append 1 at the end of the code. so the new code value of the letter E is 10001011 that is 8 bits long.

Similarly, the ASCII value of A is 1000001 and here the number of ones(1) are even so we need to add zero (0) at the end of code bits. so the new error detecting code for A is 10000010. so now all the characters have 9 bits code including the parity check bit.

So whenever a character is read from the storage or any other location of the device then first it checks for the number of ones(1). and it needs to be even. and if the number of ones(1) is odd then at least one bit is wrong in the character. and this type of error is called single error.

Another thing is that using this technique we can only counter or find the one-bit error in the code. but we cannot find or detect the two-bit errors in the code.

so instead of appending the parity bit to makes the total number of ones(1) to even we can use it to make the total number of ones(1) odd. and this type of bit is called the odd parity check bit. and remember that this functionality also only detects the single error in a code.

There are some types of code that can use more than one check bit to not only detect but also correct the errors in the code. and these types of codes are called error-correcting codes.