(module
(func (export "shift_right") (param $num i32) (param $by i32) (result i32)
;; load the number to shift and the by how many spots
local.get $num
local.get $by
;; shift and return the result
i32.shr_u
)
)
var url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console }).then(
(result) => {
const shift_right = result.instance.exports.shift_right;
let res = shift_right(0b00000000_00000000_00000000_00000111, 1);
console.log(numToBin(res));
}
);
function numToBin(num) {
return (num >>> 0).toString(2).padStart(32, "0").match(/.{1,8}/g).join("_");
}