CN Codes
CN Codes
CN Codes
package javaTpoint.JavaExample;
import java.util.*;
class HammingCodeExample {
int arr[];
int hammingCode[];
size = sc.nextInt();
arr[size - j - 1] = sc.nextInt();
System.out.print(arr[size - k - 1]);
System.out.println();
hammingCode = getHammingCode(arr);
hammingCodeSize = hammingCode.length;
System.out.print(hammingCode[(hammingCodeSize - i - 1)]);
System.out.println();
System.out.println("For detecting error at the reciever end, enter position of a bit to alter original da
ta " + "(0 for no error):");
errorPosition = sc.nextInt();
sc.close();
if(errorPosition != 0) {
hammingCode[errorPosition - 1] = (hammingCode[errorPosition - 1] + 1) % 2;
System.out.print(hammingCode[hammingCodeSize - k - 1]);
System.out.println();
int returnData[];
int size;
int i = 0, parityBits = 0 ,j = 0, k = 0;
size = data.length;
parityBits++;
else {
i++;
if(Math.pow(2, j) == i) {
returnData[(i - 1)] = 2;
j++;
}
else {
return returnData;
int parityBit = 0;
if(returnData[i] != 2) {
int k = (i + 1);
if(temp == 1) {
if(returnData[i] == 1) {
parityBit = (parityBit + 1) % 2;
return parityBit;
int pow;
int j = i + 1;
if(bit == 1) {
if(data[i] == 1) {
parityArray[pow] = (parityArray[pow] + 1) % 2;
if(finalLoc != 0) {
data[finalLoc - 1] = (data[finalLoc - 1] + 1) % 2;
System.out.print(data[size - i - 1]);
System.out.println();
else {
pow = parityBits - 1;
if(Math.pow(2, pow) != k) {
System.out.print(data[k - 1]);
}
else {
pow--;
System.out.println();
}
LEAKEY BUCKET:
import java.util.Scanner;
int n = sc.nextInt();
packets[i] = sc.nextInt();
bucketContent += packets[i];
} else {
bucketContent -= outputRate;
} else {
bucketContent = 0;
}
bucketContent -= outputRate;
} else {
bucketContent = 0;
sc.close();
}
CRC:
import java.util.*;
class CRCExample {
int size;
size = scan.nextInt();
data[i] = scan.nextInt();
size = scan.nextInt();
divisor[i] = scan.nextInt();
System.out.print(rem[i]);
System.out.print(data[i]);
}
for(int i = 0; i < rem.length-1; i++) {
System.out.print(rem[i]);
System.out.println();
sentData[i] = scan.nextInt();
receiveData(sentData, divisor);
int i;
System.out.print("Remainder : ");
if(rem[0] == 1) {
System.out.print(rem[j-1]);
else {
System.out.print(rem[j-1]);
rem[divisor.length-1] = data[i+divisor.length];
System.out.println(rem[divisor.length-1]);
return rem;
if(x == y) {
return 0;
return 1;
if(rem[i] != 0) {
return;
}
SOCKET PROGRAMMING:
SHORTEST-PATH:
import java.util.*;
import java.io.*;
import java.lang.*;
m = distance[vx];
m_index = vx;
} }
return m_index;
System.out.println("The shortest Distance from source 0th node to all other nodes are: ");
distance[j] = Integer.MAX_VALUE;
spSet[j] = false; }
distance[s] = 0;
spSet[ux] = true;
} }
printSolution(distance, totalVertex);
int grph[][] = new int[][] { { -1, 3, -1, -1, -1, -1, -1, 7, -1 },
{ -1, 4, 1, 3, -1, 5, 5, 6, -1 } };
obj.dijkstra(grph, 0);
} }