Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
The cuint npm package provides utilities for handling unsigned integers of various sizes, particularly useful in environments where native support for large integers is limited or non-existent. It allows for the creation, manipulation, and arithmetic of unsigned integers beyond JavaScript's native Number limits.
Creation of unsigned integers
This feature allows the creation of 32-bit unsigned integers. The example shows how to create a UINT32 instance and print its value.
const UINT32 = require('cuint').UINT32;
const uint = UINT32(123456789);
console.log(uint.toString());
Arithmetic operations
This feature supports basic arithmetic operations such as addition. The code sample demonstrates adding two UINT32 instances.
const UINT32 = require('cuint').UINT32;
const a = UINT32('123456789');
const b = UINT32('987654321');
const result = a.add(b);
console.log(result.toString());
Bitwise operations
This feature supports bitwise operations like AND. The example illustrates performing a bitwise AND between two UINT32 instances.
const UINT32 = require('cuint').UINT32;
const a = UINT32('4294967295');
const result = a.and(UINT32('123456789'));
console.log(result.toString());
The bignum package also provides support for large integer arithmetic. It offers more extensive functionality including support for both signed and unsigned integers, as well as more complex operations like exponentiation and division, which makes it more versatile compared to cuint.
big-integer is another package that handles large integers. Unlike cuint, which is limited to unsigned integers, big-integer supports both signed and unsigned integers and provides a richer set of features including modular arithmetic and prime testing.
Javascript does not natively support handling of unsigned 32 or 64 bits integers. This library provides that functionality, following C behaviour, enabling the writing of algorithms that depend on it.
TODO 64 bits integers not supported yet!
An unsigned 32 bits integer is represented by an object with its first 16 bits (low bits) and its 16 last ones (high bits). All the supported standard operations on the unsigned integer are then performed transparently.
e.g.
10000010000100000100010000100010 (2182104098 or 0x82104422) is represented by:
high=1000001000010000
low= 0100010000100010
NB. In case of overflow, the unsigned integer is truncated to its lowest 32 bits.
The same applies to 64 bits integers, which are split into 4 16 bits ones.
In nodejs:
npm install cuint
In the browser, include the following, and access the constructor with UINT32:
` ...
`To instantiate an unsigned 32 bits integer, do any of the following:
var UINT32 = require('cuint').UINT32 // NodeJS
UINT32( <low bits>, <high bits> )
UINT32( <number> )
UINT32( '<number>' )
UINT32( 2, 1 ) // 65538
{ remainder: null, _low: 2, _high: 1 }
UINT32( 65538 ) // 65538
{ remainder: null, _low: 2, _high: 1 }
UINT32( '65538' ) // 65538
{ remainder: null, _low: 2, _high: 1 }
UINT32( '3266489917' )
{ remainder: null, _low: 44605, _high: 49842 }
UINT32( '3266489917' ).div( UINT32( '668265263' ) )
{ remainder: { remainder: null , _low: 385 , _high: 9055 } , _low: 4 , _high: 0 }
UINT32.fromBits(<low bits>, <high bits>)*
Set the current UINT32 object with its low and high bitsUINT32.fromNumber(<number>)*
Set the current UINT32 object from a numberUINT32.fromString(<string>, <radix>)*
Set the current UINT32 object from a stringUINT32.toNumber()
Convert this UINT32 to a numberUINT32.toString(<radix>)
Convert this UINT32 to a stringUINT32.add(<uint>)*
Add two UINT32. The current UINT32 stores the resultUINT32.subtract(<uint>)*
Subtract two UINT32. The current UINT32 stores the resultUINT32.multiply(<uint>)*
Multiply two UINT32. The current UINT32 stores the resultUINT32.div(<uint>)*
Divide two UINT32. The current UINT32 stores the result.
The remainder is made available as the remainder property on the UINT32 object.
It can be null, meaning there are no remainder.UINT32.negate()
alias UINT32.not()
Negate the current UINT32UINT32.equals(<uint>)
alias UINT32.eq(<uint>)
EqualsUINT32.lessThan(<uint>)
alias UINT32.lt(<uint>)
Less than (strict)UINT32.greaterThan(<uint>)
alias UINT32.gt(<uint>)
Greater than (strict)UINT32.or(<uint>)*
Bitwise ORUINT32.and(<uint>)*
Bitwise ANDUINT32.xor(<uint>)*
Bitwise XORUINT32.shiftRight(<number>)*
alias UINT32.shiftr(<number>)*
Bitwise shift rightUINT32.shiftLeft(<number>[, <allowOverflow>])*
alias UINT32.shiftl(<number>[, <allowOverflow>])*
Bitwise shift leftUINT32.rotateLeft(<number>)*
alias UINT32.rotl(<number>)*
Bitwise rotate leftUINT32.rotateRight(<number>)*
alias UINT32.rotr(<number>)*
Bitwise rotate rightUINT32.clone()
Clone the current UINT32NB. methods with an * do modify the object it is applied to. Input objects are not modified.
MIT
Written with StackEdit.
FAQs
Unsigned integers for Javascript
The npm package cuint receives a total of 988,309 weekly downloads. As such, cuint popularity was classified as popular.
We found that cuint 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.