1
0
forked from kalmar/DALGLI0

poly generating & swapping

This commit is contained in:
Hubert Tylkowski 2018-06-19 00:45:51 +02:00
parent 966b225ba8
commit 59cc5a61df
2 changed files with 42 additions and 5 deletions

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