![]() ![]() Suppose the message that is to be sent is 00 0100 and the message received is 00 1100. TYPES OF ERROR SINGLE BIT ERROR:Īs the name suggests, in this type of error only one or single bit is changed from 0 to 1 or from 1 to 0. There are basically two types of errors in computer network which needs to be detected and corrected. It is very important to detect the error for proper and perfect transfer of information and message. So let's get started.Įrror as we all know is a situation when message received is not identical as compared to error sent. We will be seeing some standard error detecting codes which help in detecting errors. Thanks for reading this tutorial.In this article, we are going to explore about error detection in computer networks. If (b & 1) //This is used for checking odd If b is odd mean odd parity else even parity Left Shifting by double of previous operation shift So, here is the C++ implementation of the above algorithm:- #include C++ program to find parity of a number efficiently We check the odd or even by using bitwise AND operator. If the rightmost bit is 1, then n will have odd parity and if it is 0 then n will have even parity. Now, after the above operations b contain the rightmost bit of b and represent the parity of n. So when we divide the binary representation of a number into two equal halves by length & we do XOR between them, all different pairs of bits result into set bits in the result number i.e “ b” here. We know that 0 XOR 1 or 1 XOR 0 is 1, otherwise 0. We are shifting double bits of the previous operation. In the above operations, we use XOR and left shift operator. ![]() The most efficient way of finding the parity of a number is by using XOR and shifting operator as shown below. Efficient Algorithm to find parity of a number Odd Parity: If the total number of set bits (1’s) is odd, then that number has odd parity.ġ2 has even parity because it has an even number of set bits in its binary representation i.e ‘1100’.ġ4 has odd parity because it has an odd number of set bits in its binary representation i.e ‘1110’. Even Parity: If the total number of set bits (1’s) is even, then that number has even parity.Ģ. Parity of a number is a term used to tell that the total number of set bits(1’s) in its binary representation is even or odd. Here we will learn about the parity of a number, algorithm to find the parity of a number efficiently, and after that, we will see the C++ program for the same. ![]() In this tutorial, we are going to learn how to find parity of a number efficiently in C++. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |