poly generating & swapping
This commit is contained in:
parent
966b225ba8
commit
59cc5a61df
12
Zadanie-03/Zadanie-03.iml
Normal file
12
Zadanie-03/Zadanie-03.iml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
@ -1,13 +1,38 @@
|
||||
package com.tylkowski.crc;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CrcTask {
|
||||
private String message;
|
||||
private String polyGenerator;
|
||||
private short[] messageAsShortArray;
|
||||
private short[] polyGenerator;
|
||||
|
||||
public CrcTask(String message) {
|
||||
this.message = message;
|
||||
this.polyGenerator = "10001000000100001";
|
||||
this.message = message + "0000000000000000";
|
||||
convertMessageToBinaryShortArray();
|
||||
createGeneratingPoly();
|
||||
swapPolyValues();
|
||||
}
|
||||
|
||||
private void convertMessageToBinaryShortArray() {
|
||||
messageAsShortArray = new short[message.length()];
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
if (message.charAt(i) == 48) {
|
||||
messageAsShortArray[i] = 0;
|
||||
} else {
|
||||
messageAsShortArray[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createGeneratingPoly() {
|
||||
polyGenerator = new short[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
polyGenerator[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void swapPolyValues() {
|
||||
for (int i = 0; i < polyGenerator.length; i++) {
|
||||
messageAsShortArray[i] = (short) ((messageAsShortArray[i] + 1) % 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user