Answers for "convert text to binary javascript"

1

converting binary to text js

function binaryAgent(str) {

var newBin = str.split(" ");
var binCode = [];

for (i = 0; i < newBin.length; i++) {
    binCode.push(String.fromCharCode(parseInt(newBin[i], 2)));
  }
return binCode.join("");
}
binaryAgent('01000001 01110010 01100101 01101110 00100111 01110100');
//translates to "Aren't"
Posted by: Guest on October-21-2020
0

how to convert to binary in javascript

function bin(num) {
    var binn = [];
    var c;
    while (num != 1) {
        c = Math.floor(num / 2);
        binn.unshift(num % 2);
        num = c;

    }
    binn.unshift(1)
    return binn
}
//returns list of binary nos. in order
Posted by: Guest on September-08-2020
0

string to binary javascript

let num = 2020;
let x = +num.toString(2);
console.log(x);
Posted by: Guest on June-29-2020
0

convert text to binary javascript

function stringToBinary(str) {
    let strOut = "";
    for (var i = 0; i < str.length; i++) {
        strOut += str[i].charCodeAt(0).toString(2);
    }
    return strOut
}
Posted by: Guest on October-29-2021
-1

javascript convert binary to text

function binaryAgent(str) {
  let bytes = str.split(' ');
  let output = '';
    
  for (let k = 0; k < bytes.length; k++){
      output += String.fromCharCode(convertToDecimal(bytes[k]));
  }

  return output;
}

function convertToDecimal(byte) {
  let result = 0;

  byte = byte.split('');

  byte.reverse();

  for (let a = 0; a < byte.length; a++){
    if (byte[a] === '1'){
      result += 2 ** a;
    }
  }

  return result;
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Posted by: Guest on May-21-2020

Code answers related to "convert text to binary javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language