Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/donmccurdy/hex2dec
Arbitrary precision decimal↔️hexadecimal converter.
https://github.com/donmccurdy/hex2dec
Last synced: 13 days ago
JSON representation
Arbitrary precision decimal↔️hexadecimal converter.
- Host: GitHub
- URL: https://github.com/donmccurdy/hex2dec
- Owner: donmccurdy
- License: apache-2.0
- Created: 2016-07-09T23:47:46.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T13:59:00.000Z (about 2 months ago)
- Last Synced: 2024-10-15T20:41:06.741Z (27 days ago)
- Language: JavaScript
- Size: 115 KB
- Stars: 27
- Watchers: 6
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# hex2dec
[![Latest NPM release](https://img.shields.io/npm/v/hex2dec.svg)](https://www.npmjs.com/package/hex2dec)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/hex2dec)](https://bundlephobia.com/package/hex2dec)
[![License](https://img.shields.io/npm/l/hex2dec.svg)](https://github.com/donmccurdy/hex2dec/blob/master/LICENSE)
[![Build Status](https://github.com/donmccurdy/hex2dec/workflows/build/badge.svg?branch=master&event=push)](https://github.com/donmccurdy/hex2dec/actions?query=workflow%3Abuild)Arbitrary precision decimal↔️hexadecimal converter, from a [blog post](http://www.danvk.org/hex2dec.html) by [Dan Vanderkam](https://github.com/danvk). Supports non-negative integer values.
## Usage
```
npm install --save hex2dec
``````javascript
var converter = require('hex2dec');var dec = converter.hexToDec('0xFA'); // 250
var hex = converter.decToHex('250'); // '0xfa'
var hexString = converter.decToHex('250', { prefix: false }); // 'fa'
```## Why use hex2dec
`(250).toString(16) === 'fa'` and `250 === 0xFA` both work just fine, and will provide enough precision for most uses. For large (>64-bit) numbers, however, precision is lost. This utility provides a higher-precision alternative.
## License
This code may be used under the [Apache 2 license](https://github.com/donmccurdy/hex2dec/blob/master/LICENSE).