![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@lemire/jstypes
Advanced tools
Doing C-like arithmetic and logical operations in JavaScript (full 64-bit support)
The jstypes library uses WebAssembly to support C-like arithmetic and logical operations in JavaScript. The essential strategy is to represent all numbers as string representing 64-bit hexadecimal numbers (we call them "hex64"). Conceptually these strings represent the content of a 64-bit register. These strings can be added, multiplied and so forth, resulting in other similar (hex64) strings. We can also convert these hex64 strings to other representations like 32-bit signed integers of 8-bit unsigned integers, as a processor would. Thus we use strings between "0000000000000000" and "FFFFFFFFFFFFFFFF" as inputs. Some instructions also expect a bit width parameter (out of 8, 16, 32, and 64). When specifying a bit width of 32, only the least significant 32 bits are processed. Thus we use strings between "0000000000000000" and "FFFFFFFFFFFFFFFF" as inputs. Some instructions also expect a bit width parameter (out of 8, 16, 32, and 64). When specifying a bit width of 32, only the least significant 32 bits are processed.
The following JavaScript code
console.log("FF000000000000 + 00111111111111 (32 bits) = "
+jstypes.hex64_add("FF000000000000","00111111111111",32));
console.log("FF000000000000 * 00111111111111 (64 bits) = "
+jstypes.hex64_multiply("FF000000000000","00111111111111",64));
console.log("FF000000000000 shifted by 35 bits in signed mode is = "
+jstypes.hex64_shift_right_signed("FF00000000000000",35, 64));
should output...
FF000000000000 + 00111111111111 (32 bits) = 11111111
FF000000000000 * 00111111111111 (64 bits) = FFEF000000000000
FF000000000000 shifted by 35 bits in signed mode is = FFFFFFFFFFE00000
We support the following functions:
Go to a new directory and load the library:
npm init
npm i @lemire/jstypes
Create and run the following script (e.g., as test.js):
var jstypes = require("@lemire/jstypes")
jstypes.init().then(ready => {
console.log("FF000000000000 + 00111111111111 (32 bits) = "
+jstypes.hex64_add("FF000000000000","00111111111111",32));
console.log("FF000000000000 * 00111111111111 (64 bits) = "
+jstypes.hex64_multiply("FF000000000000","00111111111111",64));
console.log("FF000000000000 shifted by 35 bits in signed mode is = "
+jstypes.hex64_shift_right_signed("FF00000000000000",35, 64));
}).
catch(error => {
console.log(error.message);
});
FAQs
Doing C-like arithmetic and logical operations in JavaScript (full 64-bit support)
The npm package @lemire/jstypes receives a total of 2 weekly downloads. As such, @lemire/jstypes popularity was classified as not popular.
We found that @lemire/jstypes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.