Help me fix the code for binary to text translator
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi experts,
I am developing one binary translator like this: https://www.gradecalculator.tech/binary-translator/
The confusion is only in javascript function. The code is given below that I used in my tool. I don't know what's wrong with the code but I get error in console like ($ is not a function). Please help me to solve this issue. Thanks in advance.
function BtoText()
{
var bin = $("#bin").val();
var i=$(".calc select")[0].selectedIndex;
if( i==0 )
bin = bin.match(/[0-1]{1,8}/g);
else
bin = bin.match(/[0-1]*/g).filter(function (el) {
return el!="";
});
if( !bin ) return;
len = bin.length;
if( len==0 ) return;
txt='';
for(i=0; i<len; i++)
{
b = bin[i];
code = parseInt(b,2);
t = String.fromCharCode(code);
txt += t;
}
$("#txt").val(txt);
}
0 Kommentare
Antworten (1)
David Hill
am 9 Jan. 2020
You need to decide what the format of your input binary will look like. Will you force the input to be multiples of 8-bits? If your input is a character string of binary numbers at multiple of 8-bits long, then:
function Output=b2text(Input)%Input'010010000110010101101100011011000110111101110111'
Output=char(bin2dec(reshape(Input,8,[])')');
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!