Procs
func customLiteral(T: type SomeBigInteger; s: static string): T:type
- Source Edit
func dumpHex(a: StInt or StUint; order: static[Endianness] = bigEndian): string {. ...gcsafe.}
-
Stringify an int to hex.
Note. Leading zeros are not removed. Use toString(n, base = 16)/toHex instead.
You can specify bigEndian or littleEndian order. i.e. in bigEndian:
- 1.uint64 will be 00000001
- (2.uint128)^64 + 1 will be 0000000100000001
in littleEndian:
- 1.uint64 will be 01000000
- (2.uint128)^64 + 1 will be 0100000001000000
func fromDecimal(T: typedesc[StUint | StInt]; s: string): T:type {.inline, ...gcsafe.}
- Source Edit
func parse[bits: static[int]](input: string; T: typedesc[StInt[bits]]; radix: static[uint8] = 10): T:type {....gcsafe.}
- Parse a string and store the result in a StInt[bits] or StUint[bits]. Source Edit
func parse[bits: static[int]](input: string; T: typedesc[StUint[bits]]; radix: static[uint8] = 10): T:type {....gcsafe.}
- Parse a string and store the result in a StInt[bits] or  StUint[bits]. Source Edit
func readIntBE[bits: static[int]](ba: openArray[byte]): StInt[bits] {.noinit, inline, ...raises: [], inline, noinit, ...gcsafe.}
-
Convert a big-endian array of (bits div 8) Bytes to an StInt[bits] (in native host endianness).
Input:
- a big-endian openArray of size (bits div 8) at least
Returns:
- A signed integer of the same size with bits bits
func readIntLE[bits: static[int]](ba: openArray[byte]): StInt[bits] {.noinit, inline, ...raises: [], inline, noinit, ...gcsafe.}
-
Convert a lettle-endian array of (bits div 8) Bytes to an StInt[bits] (in native host endianness).
Input:
- a little-endian openArray of size (bits div 8) at least
Returns:
- A signed integer of the same size with bits bits
func readUintBE[bits: static[int]](ba: openArray[byte]): StUint[bits] {.noinit, inline, ...raises: [], inline, noinit, ...gcsafe.}
-
Convert a big-endian array of (bits div 8) Bytes to an StUint[bits] (in native host endianness).
Input:
- a big-endian openArray of size (bits div 8) at least
Returns:
- A unsigned integer of the same size with bits bits
func readUintLE[bits: static[int]](ba: openArray[byte]): StUint[bits] {.noinit, inline, ...raises: [], inline, noinit, ...gcsafe.}
-
Convert a little-endian array of (bits div 8) Bytes to an StUint[bits] (in native host endianness).
Input:
- a little-endian openArray of size (bits div 8) at least
Returns:
- A unsigned integer of the same size with bits bits
func stint(a: StInt; bits: static[int]): StInt[bits] {....raises: [], gcsafe.}
-
Signed int to signed int conversion.
Will raise exception if input does not fit into destination.
Source Edit func stuint(a: StInt; bits: static[int]): StUint[bits] {.inline, ...raises: [], gcsafe.}
-
Signed int to unsigned int conversion.
Bigger to smaller bits conversion, the result is truncated.
Source Edit func toByteArrayBE[bits: static[int]](n: StUint[bits]): array[bits div 8, byte] {. noinit, inline, ...deprecated: "endians2.toBytesBE", raises: [], inline, noinit, ...gcsafe.}
-
Convert a StUint[bits] to to a big-endian array of bits div 8 bytes.
Input:
- an unsigned integer
Returns:
- a big-endian array of the same size
func truncate(num: StInt; T: typedesc[SomeInteger]): T:type {.inline, ...raises: [], gcsafe.}
-
Extract the int, uint, int8-int64 or uint8-uint64 portion of a multi-precision integer. Note that int and uint are 32-bit on 32-bit platform.
For unsigned result type, result is modulo 2^(sizeof T in bit).
For signed result type, result is undefined if input does not fit in the target type.
Source Edit func truncate(num: StUint; T: typedesc[SomeInteger]): T:type {.inline, ...raises: [], gcsafe.}
-
Extract the int, uint, int8-int64 or uint8-uint64 portion of a multi-precision integer. Note that int and uint are 32-bit on 32-bit platform.
For unsigned result type, result is modulo 2^(sizeof T in bit).
For signed result type, result is undefined if input does not fit in the target type.
Source Edit
Templates
template initFromBytesBE(x: var StInt; ba: openArray[byte]) {..}
- Source Edit
template initFromBytesBE(x: var StUint; ba: openArray[byte]) {..}
- Source Edit
template initFromBytesLE(x: var StInt; ba: openArray[byte]) {..}
- Source Edit
template initFromBytesLE(x: var StUint; ba: openArray[byte]) {..}
- Source Edit
template leastSignificantWord(a: SomeBigInteger): Word {..}
- Source Edit
template mostSignificantWord(a: SomeBigInteger): Word {..}
- Source Edit
template signedWordType(_: type SomeBigInteger): type {..}
- Source Edit
template toByteArrayLE[bits: static[int]](n: StInt[bits]): array[bits div 8, byte] {....deprecated: "endians2.toBytesLE".}
-
Convert a StInt[bits] to to a little-endian array of bits div 8 bytes.
Input:
- an signed integer
Returns:
- a little-endian array of the same size
template toByteArrayLE[bits: static[int]](n: StUint[bits]): array[bits div 8, byte] {....deprecated: "endians2.toBytesLE".}
-
Convert a StUint[bits] to to a little-endian array of bits div 8 bytes.
Input:
- an unsigned integer
Returns:
- a little-endian array of the same size
Exports
-
fromBytes, fromBytes, fromBytesLE, toBytesBE, fromBytesBE, fromBytesLE, toBytesLE, toBytes, fromBytesLE, fromBytesBE, toBytesLE, toBytes, toBytesBE, fromBytesBE, fromBytes, fromBytes, fromBytes, fromBytes, toBytes, toBytes, fromBytesLE, fromBytesLE, fromBytesLE, toBytesLE, toBytesLE, fromBytesBE, fromBytesBE, fromBytesBE, toBytesBE, toBytesBE