0 Pluspunkte 0 Minuspunkte

Wie kann ich eine IP als String

192.168.0.1

in binär anzeigen in Javascript?

11000000.10101000.00000000.00000001
von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

Du kannst eine Funktion dazu schreiben

function ipToBinary(ipAddress) {
  const binaryParts = [];
  const octets = ipAddress.split('.');
  for (let i = 0; i < octets.length; i++) {
    const binary = parseInt(octets[i]).toString(2).padStart(8, '0');
    binaryParts.push(binary);
  }
  return binaryParts.join('.');
}

von (716 Punkte)