zad 02,03 #37

Closed
s426159 wants to merge 14 commits from s426159/DALGLI0:master into master
2 changed files with 18 additions and 5 deletions
Showing only changes of commit e8f67f6e9e - Show all commits

View File

@ -6,7 +6,7 @@ switch (flag) {
console.log(crc.encode(message));
break;
case '-d':
console.log(crc.decode(message));
break;
default:
throw "incorect flag"

21
crc.js
View File

@ -12,11 +12,19 @@ const to_bin = a => {
}
const to_ascii = a => {
a = a.join('');
return String.fromCharCode(parseInt(a, 2));;
a = parseInt(a, 2);
console.log(a)
//nie znalazłem innego sposobu w js na osiągniecie tego efektu..
if (a < 126) //ponieważ wieksze liczby nie należą do typowego Ascii
return String.fromCharCode(a);
else {
return "0x" + a.toString(16);
// return "\\x" + a.toString(16); //escape \ nie wiem czemu dobrze nie działą i i tak wypisuje \\
}
}
const fcs = m => {
bits = m.map(to_bin); //message in binary
bits = bits.join('').split('').reverse(); //reverse binary decoded message
@ -61,4 +69,9 @@ function encode(m) {
}
exports.encode = encode;
exports.encode = encode;
function decode(m) {
}
exports.decode = decode;