hex2dec
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/hex2dec package

1.1.2 • Public • Published

hex2dec

Latest NPM release Minzipped size License Build Status

Arbitrary precision decimal↔️hexadecimal converter, from a blog post by Dan Vanderkam. Supports non-negative integer values.

Usage

npm install --save hex2dec
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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.2
    227,159
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.2
    227,159
  • 1.1.1
    7
  • 1.1.0
    152
  • 1.0.1
    57,121
  • 1.0.0
    12

Package Sidebar

Install

npm i hex2dec

Weekly Downloads

224,369

Version

1.1.2

License

Apache-2.0

Unpacked Size

17.8 kB

Total Files

8

Last publish

Collaborators

  • donmccurdy