0.0.3 • Published 10 years ago

ultduint v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Unlimited Unsigned Integer - Unsigned integers, without limits

Working on an interesting project, I found myself with the need to use 32-bit unsigned integers of fixed size. After a while, working at the same project, I found myself with the need to use 64-bit unsigned integers of fixed size. Looking around for a solution, I didn't find any module that could help me, so I decided to write this little module.

Create a new Unlimited Usigned Integer is easy. All that you need is to specify a size in terms of 32*N bit, as follows:

var UltdUInt = require('ultduint');
var uu = new UltdUInt(64);

Please, notice that creating a new Unlimited Usigned Integer with a size that isn't a multiple of 32 or with no size at all will create an empty object of size 0 (that is, of course, a multiple of 32).

That's all.

There are some available functions which can be used to interact with these kind of objects and to compare them, as follows:

var UltdUInt = require('ultduint');
var uu = new UltdUInt(32); // it's 0x00000000

uu.next(); // it's 0x00000001
uu.prev(); // it's 0x00000000
uu.add(1); // it's 0x00000001
uu.add(uu); // it's 0x00000002
uu.sub(1); // it's 0x00000001
uu.sub(uu); // it's 0x00000000
uu.eq(uu); // it's true
uu.neq(uu); // it's false
uu.gt(uu); // it's false
uu.lt(uu); // it's false
uu.ge(uu); // it's true
uu.le(uu); // it's true

uu.size(); // it's 32
uu.internal_rep() // it's expressed by means of Buffer, LE format
uu.rep() // it's expressed by means of Buffer, LE format