https://github.com/coderaiser/read-uint
read an unsigned integer from buffer
https://github.com/coderaiser/read-uint
buffer int64 javascript nodejs readuint
Last synced: 7 months ago
JSON representation
read an unsigned integer from buffer
- Host: GitHub
- URL: https://github.com/coderaiser/read-uint
- Owner: coderaiser
- Created: 2018-07-31T19:52:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-11T10:43:18.000Z (over 5 years ago)
- Last Synced: 2025-05-31T21:52:37.379Z (10 months ago)
- Topics: buffer, int64, javascript, nodejs, readuint
- Language: JavaScript
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
Awesome Lists containing this project
README
# Read UInt [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
Read an unsigned integer from `buffer`. Similar to [buf.readIntBE](https://nodejs.org/dist/latest-v10.x/docs/api/buffer.html#buffer_buf_readintbe_offset_bytelength) but without `byteLength` limitation.
## Install
```
npm i read-uint
```
## How to use?
```js
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
[NPMIMGURL]: https://img.shields.io/npm/v/read-uint.svg?style=flat&longCache=true
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/read-uint/master.svg?style=flat&longCache=true
[DependencyStatusIMGURL]: https://img.shields.io/david/coderaiser/read-uint.svg?style=flat&longCache=true
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat&longCache=true
[NPMURL]: https://npmjs.org/package/read-uint "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/read-uint "Build Status"
[DependencyStatusURL]: https://david-dm.org/coderaiser/read-uint "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"