Help me fix the code for binary to text translator
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
David Hill
le 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 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!