2complement 中文文档教程

发布于 5年前 浏览 23 项目主页 更新于 3年前

2complement

像 NodeJS 中的魅力一样从 2 的补码来回

Install

npm i 2complement

Usage

decode = require('2complement');

console.log(decode.int2complement(32765).toString(2));
//1000000000000011

console.log(decode.complement2int(0b1000000000000011))
//-32765

console.log(decode.complement2int(decode.int2complement(-2000)));
//-2000

console.log("You rock");
//just a motivational quote. But you do <3

Methods

  • decode.complement2int(_2complement[,nBits]):
    • _2complement: Number to be converted to int
    • nBits: (optional) Number of bits. 16 is the default
  • decode.int2complement(number[,nBits]):
    • number: Number to be converted to 2's complement
    • nBits: (optional) Number of bits. 16 is the default

2complement

Go back and forth from 2's complement like a charm in NodeJS

Install

npm i 2complement

Usage

decode = require('2complement');

console.log(decode.int2complement(32765).toString(2));
//1000000000000011

console.log(decode.complement2int(0b1000000000000011))
//-32765

console.log(decode.complement2int(decode.int2complement(-2000)));
//-2000

console.log("You rock");
//just a motivational quote. But you do <3

Methods

  • decode.complement2int(_2complement[,nBits]):
    • _2complement: Number to be converted to int
    • nBits: (optional) Number of bits. 16 is the default
  • decode.int2complement(number[,nBits]):
    • number: Number to be converted to 2's complement
    • nBits: (optional) Number of bits. 16 is the default
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文