-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathParityBit.java
More file actions
31 lines (27 loc) · 805 Bytes
/
Copy pathParityBit.java
File metadata and controls
31 lines (27 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Scanner;
public class ParityBit {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String parity;
System.out.print("Enter Parity Bit: ");
parity = input.next();
System.out.println("8 bit:"+Paritybit(parity));
}
public static String Paritybit(String parity){
int lenp = parity.length();
int count=0;
String charp;
for(int i=0;i<lenp;i++){
if(parity.substring(i,i+1).equals("1")){
count++;
}
}
System.out.println("Count: "+count);
if(count%2==0){
parity=""+parity+0;
}else{
parity=""+parity+1;
}
return parity;
}
}