Files
common/packages/util/docs/bn.md
T
Jaco Greeff b5c5734c7c Add Blake2s & XXHash utility functions (#66)
* Initial split of util & util-crypto

* Add initial XXHash version

* Blake2s wit tests & documentation

* Add sha512 (from NaCl)

* Add randomBytes (from NaCl)

* Flow fixes

* Update documentation

* Update latest @polkadot/dev
2018-01-25 14:13:43 +01:00

36 lines
740 B
Markdown

# bn
Utility methods to convert to and from `BN` objects
- [bnFromHex](#bnfromhex) Creates a BN.js bignumber object from a hex string.
- [bnToHex](#bntohex) Creates a hex value from a BN.js bignumber object.
## bnFromHex
Creates a BN.js bignumber object from a hex string. [(alias of hexToBn)](hex.md#hextobn)
```js
bnFromHex (value?: string): BN
```
## bnToHex
Creates a hex value from a BN.js bignumber object.
```js
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.
```js
import BN from 'bn.js';
import { bnToHex } from '@polkadot/util';
bnToHex(new BN(0x123456)); // => '0x123456'
```