2.0.0 • Published 4 years ago

read-uint v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Read UInt License NPM version Dependency Status Build Status

Read an unsigned integer from buffer. Similar to buf.readIntBE but without byteLength limitation.

Install

npm i read-uint

How to use?

const {readUIntBE, readUIntLE} = require('read-uint');
const buf = Buffer.from([0xff, 0xfe, 0xff, 0xfd, 0xfb, 0xfa, 0xf0, 0xf1]);

readUIntBE(buf, 0);
// returns
'0xfffefffdfbfaf0f1';

readUIntLE(buf, 0);
// returns
'0xf1f0fafbfdfffe';

// same with array
const array = [0xff, 0xfe, 0xff, 0xfd, 0xfb, 0xfa, 0xf0, 0xf1];
readUIntBE(array, 0);
// returns
'0xfffefffdfbfaf0f1';

// set byte length
readUIntBE(buf, 0, 4);
// returns
'0xfffefffd';

readUIntLE(buf, 0, 4);
// returns
'0xf1f0fafb';

// convert to BigInt
const a = readUIntBE(buf, 0);
const number = BigInt(parseInt(a, 16));

License

MIT

2.0.0

4 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago