JSFiddle - React, Tailwind, and code Playground
HTML
<input id="n1" type="textarea"></input>
<input id="n2" type="textarea"></input>
<br><br>
<button id="and">AND</button>
<button id="or">OR</button>
<button id="xor">XOR</button>
<button id="not">NOT</button>
<button id="lshift">LSHIFT</button>
<button id="rshift">RSHIFT</button>
<br>
<pre id="out"></pre>
JavaScript
/* super swaggy bitwise operators without the binary part
* by Zro716 on Scratch
* for aiding comp09 on Scratch
* I blame nutella for all errors in code
* happy debugging suckers!
*/
document.getElementById("and").addEventListener('click',do_and);
document.getElementById("or").addEventListener('click',do_or);
document.getElementById("xor").addEventListener('click',do_xor);
document.getElementById("not").addEventListener('click',do_not);
document.getElementById("lshift").addEventListener('click',do_lsh);
document.getElementById("rshift").addEventListener('click',do_rsh);
function do_and() {
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
document.getElementById("out").innerHTML += a+" AND "+b+" = "+AND(a,b)+"<br>"; }
function do_or() {
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
document.getElementById("out").innerHTML +=
a+" OR "+b+" = "+OR(a,b)+"<br>"; }
function do_xor() {
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
document.getElementById("out").innerHTML +=
a+" XOR "+b+" = "+XOR(a,b)+"<br>"; }
function do_not() {
var a = document.getElementById("n1").value;
document.getElementById("out").innerHTML +=
"NOT "+a+" = "+NOT(a)+"<br>"; }
function do_lsh() {
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
document.getElementById("out").innerHTML +=
a+" << "+b+" = "+LSHIFT(a,b)+"<br>"; }
function do_rsh() {
var a = document.getElementById("n1").value;
var b = document.getElementById("n2").value;
document.getElementById("out").innerHTML +=
a+" >> "+b+" = "+RSHIFT(a,b)+"<br>"; }
function AND(n1,n2) {
var byteVal = 1;
var result = 0;
while (n1 > 0 || n2 > 0) {
if (n1 % 2 > 0 && n2 % 2 > 0) { result+=byteVal; }
n1 = Math.floor(n1 / 2);
n2 = Math.floor(n2 / 2);
...