Zadanie 3 - CRC - wersja innym inputem #31

Closed
s426271 wants to merge 14 commits from s426271/DALGLI0:Zadanie-3 into master
2 changed files with 42 additions and 5 deletions
Showing only changes of commit 59cc5a61df - Show all commits

12
Zadanie-03/Zadanie-03.iml Normal file
View 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>

View File

@ -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);
}
}
}