Files
common/packages/util/docs/bn.md
T
Jaco Greeff e832aebb07 Introduce @polkadot/util-rlp (#76)
* Add toU8a conversions

* Add u8a utilities

* @polkadot/rlp with encoding

* Decoding test runthrough

* Update util locations

* Convert util-triehash to use util-rlp

* Allow keccak from Uint8Array

* Pass Uint8Array to keccak input

* Update documentation

* Skip some doc generation

* Update @polkadot/dev

* Update doc typo

* Update allocations

* Retrieve tests from ethereumjs-testing

* Simplify test retrieval

* Exclude etereumjs-testing from flow
2018-02-08 14:50:54 +01:00

1.1 KiB

bn

Utility methods to convert to and from BN objects

  • bnFromHex Creates a BN.js bignumber object from a hex string.
  • bnToHex Creates a hex value from a BN.js bignumber object.
  • bnToU8a Creates a Uint8Array object from a BN.

bnFromHex

Creates a BN.js bignumber object from a hex string. (alias of hexToBn)

bnFromHex (value?: string): BN

bnToHex

Creates a hex value from a BN.js bignumber object.

bnToHex (value?: BN): string

null inputs returns a 0x result, BN values return the actual value as a 0x prefixed hex value. Anything that is not a BN object throws an error.

import BN from 'bn.js';
import { bnToHex } from '@polkadot/util';

bnToHex(new BN(0x123456)); // => '0x123456'

bnToU8a

Creates a Uint8Array object from a BN.

bnToU8a (value?: BN): Uint8Array

null/undefined/NaN inputs returns an empty Uint8Array result. BN input values return the actual bytes value converted to a Uint8Array.

import { bnToU8a } from '@polkadot/util';

bnToU8a(new BN(0x1234)); // => [0x12, 0x34]