From e8f67f6e9e24590b1d126c23e6c75d8cfd81121e Mon Sep 17 00:00:00 2001 From: Kacper Kruczek Date: Sun, 1 Jul 2018 14:26:14 +0200 Subject: [PATCH] 03 encoding unicode --- 03-rozwiazanie.js | 2 +- crc.js | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/03-rozwiazanie.js b/03-rozwiazanie.js index 148e7bc..7532bb6 100644 --- a/03-rozwiazanie.js +++ b/03-rozwiazanie.js @@ -6,7 +6,7 @@ switch (flag) { console.log(crc.encode(message)); break; case '-d': - + console.log(crc.decode(message)); break; default: throw "incorect flag" diff --git a/crc.js b/crc.js index ca3fa1e..d9ade17 100644 --- a/crc.js +++ b/crc.js @@ -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; \ No newline at end of file +exports.encode = encode; + +function decode(m) { + +} +exports.decode = decode; \ No newline at end of file