Showing posts with label Computer Networks. Show all posts
Showing posts with label Computer Networks. Show all posts

ERROR CHECKING BY PARITY BIT


import java.util.*;
public class Parity_bit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the data bit");
String abc = sc.nextLine();
int len = abc.length();
int count1 = 0;
for (int i = 0; i < len; i++) {
if (abc.charAt(i) == '1') {
count1++;
}
}
System.out.println("No of 1 in string is " + count1);
if (count1 % 2 == 0) {
System.out.println("No of 1 is even ");
}
if (count1 % 2 != 0) {
System.out.println("No of 1 is odd ");
}
System.out.println("Enter the parity bit");
String new_bit = sc.nextLine();
String bitnew = abc + new_bit;
System.out.println("The binary data after parity bit addition is " + bitnew);
int rn = 0 + (int) (Math.random() * (len - 0) + 1);
System.out.println("random position is " + rn);
String rn_pos_chg = bitnew.substring(0, rn - 1) + "1" + bitnew.substring(rn);
System.out.println("The random bit is genrated data is:" + rn_pos_chg);
int count = 0;
for (int i = 0; i < len + 1; i++) {
if (rn_pos_chg.charAt(i) == '1') {
count++;
}
}
System.out.println("No of 1 in string is " + count);
if (count % 2 == 0) {
System.out.println("No if 1 is even thus it does not contain error");
}
if (count % 2 != 0) {
System.out.println("No if 1 is odd so it contain error");
}
}
}

PERFECT NUMBER

PERFECT NUMBER:-no which is sum of its proper divisor(proper divisor:- no which completely divide with no remainder)

package perfect_number;

import java.util.Scanner;
public class Perfect_number
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int number = sc.nextInt();
int sum = 0;
for (int i = 1; i < (number - 1); i++)
{
int divisorcheck = number % i;
if (divisorcheck == 0)
sum = sum + i;
}
if (sum == number)
System.out.println("perfect number : " + number);
else
System.out.println("non-perfect " + number);
}
}
/**documentation comment
* just make a loop before that input number and check for number divisibility by modulus operation with all succeeding number
* if modulus satisfies then sum all those satisfying no and compare with the given entered number
*/

                          OUTPUT

Enter the number
6
perfect number : 6

ERROR CORRECTION AND DETECTION in computer networks

  • PARITY CHECK:For even parity:if an even number of 1 is present then it is ok else add 1  to make an even number of 1 in the transmitting message.At the receiver side, an even number of 1 is checked if true then ok else error in the message is reflected.                     
  • CYCLIC REDUNDANCY CHECK: u will be given a generator function and a binary message . Count digit of generator function(let us say, n), add n-1 zero to the message and divide it.Add the remainder  to the binary message .This is your transmitted message .At the receiver side, it is transmitted message is divide with generator function and if remainder == zero then no error else error in  the message.
  • INTERNET CHECKSUM METHOD: Add numbers, convert to the binary, make a group of 4 and do module 2 operation . convert this remainder value to decimal and add it original decimal value. This is your transmitted message .At the receiver side , again do the same technique and at last take the 1's complement of the remainder.If it is all zero then no error else error in transmitting the message.