forked from kalmar/DALGLI0
03 encoding unicode
This commit is contained in:
parent
140e6a4606
commit
e8f67f6e9e
@ -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
21
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;
|
||||
exports.encode = encode;
|
||||
|
||||
function decode(m) {
|
||||
|
||||
}
|
||||
exports.decode = decode;
|
Loading…
Reference in New Issue
Block a user