1
0
forked from kalmar/DALGLI0

03 encoding unicode

This commit is contained in:
Kacper Kruczek 2018-07-01 14:26:14 +02:00
parent 140e6a4606
commit e8f67f6e9e
2 changed files with 18 additions and 5 deletions

View File

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

21
crc.js
View File

@ -12,11 +12,19 @@ const to_bin = a => {
} }
const to_ascii = a => { const to_ascii = a => {
a = a.join(''); 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 => { const fcs = m => {
bits = m.map(to_bin); //message in binary bits = m.map(to_bin); //message in binary
bits = bits.join('').split('').reverse(); //reverse binary decoded message 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;