Java Program for block parity
/*java program for block parity or double parity (block parity).
Calculating each column of multiple messages to check if it is even or odd. In Case of even value add 1 otherwise 0 to make even parity of column
eg.
10110101
11110011
_________
01000110
*/
import java.util.*;
class DjParity1
{
int i,j,k,l;
String ans="";
public void blockParity()
{
System.out.println("How many message you want to send: ");
Scanner s=new Scanner(System.in);
i=s.nextInt();
String msg[]=new String[i];
Scanner s1=new Scanner(System.in);
for(j=0;j<i;j++)
{
System.out.println("Enter your msg value[0/1] 8 bit: ");
msg[j]=s1.nextLine();
}
for(k=0;k<msg[0].length();k++)
{
//System.out.println("hello "+msg[k]);
int a=0;
for(l=0;l<i;l++)
{
a+=msg[l].charAt(k);
//System.out.println("Your msg: "+msg[l]);
}
if(a%2==0)
{
ans+="0";
}
else
{
ans+="1";
}
}
System.out.println("ans: "+ans);
}
}
class DjBlockParity
{
public static void main(String args[])
{
DjParity1 obj=new DjParity1();
obj.blockParity();
}
}
Calculating each column of multiple messages to check if it is even or odd. In Case of even value add 1 otherwise 0 to make even parity of column
eg.
10110101
11110011
_________
01000110
*/
import java.util.*;
class DjParity1
{
int i,j,k,l;
String ans="";
public void blockParity()
{
System.out.println("How many message you want to send: ");
Scanner s=new Scanner(System.in);
i=s.nextInt();
String msg[]=new String[i];
Scanner s1=new Scanner(System.in);
for(j=0;j<i;j++)
{
System.out.println("Enter your msg value[0/1] 8 bit: ");
msg[j]=s1.nextLine();
}
for(k=0;k<msg[0].length();k++)
{
//System.out.println("hello "+msg[k]);
int a=0;
for(l=0;l<i;l++)
{
a+=msg[l].charAt(k);
//System.out.println("Your msg: "+msg[l]);
}
if(a%2==0)
{
ans+="0";
}
else
{
ans+="1";
}
}
System.out.println("ans: "+ans);
}
}
class DjBlockParity
{
public static void main(String args[])
{
DjParity1 obj=new DjParity1();
obj.blockParity();
}
}
Comments
Post a Comment