我正在尝试学习二进制并为我提出的编程想法构建一个库,以更好地理解 Javascript 和基本编程技术。当将字符串值转换为其二进制形式时,我注意到由于某种原因,Node 无法接收该字符串的 0 和 1 值。我将学习如何将字符串转换为二进制形式,然后搜索它们以找到要从所述字符串中删除的某些值。
关于如何输出某个字符串的 0 和 1 的二进制表示有什么想法吗?
let example_one = 'A';
let buf = Buffer.from(example_one, 'binary');
for (let i = 0; i < buf.length; i++) {
console.log(`Example 1: ${buf[i]}`)
}
// Example 1:
// A
let example_two = Buffer.alloc(10);
console.log(example_two);
// Example 2: (Some 0's finally appear, do not understand it though
// <Buffer 00 00 00 00 00 00 00 00 00 00>
let example_three = Buffer.from("B", "binary");
console.log(`Example 3: ${example_three}`);
// Example …Run Code Online (Sandbox Code Playgroud) 我正在运行 Node v11.xx,并收到 V8 运行时函数的错误。
let operand = 3;
function square() {
return operand * operand;
}
square()
%OptimizeFunctionOnNextCall(square);
square()
Run Code Online (Sandbox Code Playgroud)
运行:
node --allow-natives-syntax -trace_opt -trace_deopt main.js
Run Code Online (Sandbox Code Playgroud)
收到错误
ReferenceError: OptimizeFunctionOnNextCall is not defined
Run Code Online (Sandbox Code Playgroud)
我认为这个运行时函数仍然包含在内,或者我做错了什么。