https://github.com/fabiospampinato/int32-encoding
Int32 encoding, a simple way to convert 32-bit signed integers to Uint8Arrays, and vice versa.
https://github.com/fabiospampinato/int32-encoding
encoding int32 uint8array
Last synced: 4 months ago
JSON representation
Int32 encoding, a simple way to convert 32-bit signed integers to Uint8Arrays, and vice versa.
- Host: GitHub
- URL: https://github.com/fabiospampinato/int32-encoding
- Owner: fabiospampinato
- License: mit
- Created: 2023-08-07T19:24:54.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-15T02:28:42.000Z (over 1 year ago)
- Last Synced: 2025-10-13T06:32:15.769Z (8 months ago)
- Topics: encoding, int32, uint8array
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Int32 Encoding
Int32 encoding, a simple way to convert 32-bit signed integers to Uint8Arrays, and vice versa.
The produced Uint8Array will always be 4-bytes long.
## Install
```sh
npm install int32-encoding
```
## Usage
```ts
import Int32 from 'int32-encoding';
{ // It works with positive 32-bit numbers
const encoded = Int32.encode ( 1234567890 ); // => Uint8Array(4) [73, 150, 2, 210]
const decoded = Int32.decode ( new Uint8Array ([ 73, 150, 2, 210 ]) ); // => 1234567890
}
{ // It works with negative 32-bit numbers
const encoded = Int32.encode ( -1234567890 ); // => Uint8Array(4) [182, 105, 253, 46]
const decoded = Int32.decode ( new Uint8Array ([ 182, 105, 253, 46 ]) ); // => -1234567890
}
```
## License
MIT © Fabio Spampinato