stint/io

Search:
Group by:
Source   Edit  

Procs

func `$`(num: StInt or StUint): string {.inline, ...gcsafe.}
Source   Edit  
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
Source   Edit  
func fromDecimal(T: typedesc[StUint | StInt]; s: string): T:type {.inline,
    ...gcsafe.}
Source   Edit  
func fromHex(T: typedesc[StUint | StInt]; s: string): T:type {.inline, ...gcsafe.}
Convert an hex string to the corresponding unsigned integer. Source   Edit  
func hexToUint[bits: static[int]](hexString: string): StUint[bits] {.inline,
    ...gcsafe.}
Convert an hex string to the corresponding unsigned integer. 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
Source   Edit  
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
Source   Edit  
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
Source   Edit  
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
Source   Edit  
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 stint(a: StUint; bits: static[int]): StInt[bits] {.inline, ...raises: [],
    gcsafe.}

Signed int to unsigned int conversion.

Will raise exception if input does not fit into destination.

Source   Edit  
func stint[T: SomeInteger](n: T; bits: static[int]): StInt[bits] {.inline,
    ...raises: [], inline, ...gcsafe.}
Converts an integer to an arbitrary precision signed integer. 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 stuint(a: StUint; bits: static[int]): StUint[bits] {.inline, ...raises: [],
    gcsafe.}

Unsigned int to unsigned int conversion.

Smaller to bigger bits conversion will have the same value.

Bigger to smaller bits conversion, the result is truncated.

Source   Edit  
func stuint[T: SomeInteger](n: T; bits: static[int]): StUint[bits] {.inline,
    ...raises: [], inline, ...gcsafe.}
Converts an integer to an arbitrary precision integer. Source   Edit  
func swap(a, b: var (StUint | StInt)) {....raises: [], gcsafe.}
Source   Edit  
func to(a: SomeInteger; T: typedesc[StInt]): T:type {....raises: [], inline, ...gcsafe.}
Source   Edit  
func to(a: SomeUnsignedInt; T: typedesc[StUint]): T:type {....raises: [], inline,
    ...gcsafe.}
Source   Edit  
func toByteArrayBE[bits: static[int]](n: StUint[bits]): array[bits div 8, byte] {.
    noinit, inline, ...deprecated: "endians2.toBytesBE", raises: [], inline,
    noinit, ...gcsafe.}
Deprecated: endians2.toBytesBE

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
Source   Edit  
func toHex[bits: static[int]](num: StInt[bits] or StUint[bits]): string {.
    inline, ...gcsafe.}

Convert to a hex string. Output is considered a big-endian base 16 string.

Leading zeros are stripped. Use dumpHex instead if you need the in-memory representation.

Source   Edit  
func toString[bits: static[int]](num: StInt[bits]; radix: static[uint8] = 10): string {.
    ...gcsafe.}

Convert a StInt or StUint to string.

In case of negative numbers:

  • they are prefixed with "-" for base 10.
  • if not base 10, they are returned raw in two-complement form.
Source   Edit  
func toString[bits: static[int]](num: StUint[bits]; radix: static[uint8] = 10): string {.
    ...gcsafe.}

Convert a StInt or StUint to string.

In case of negative numbers:

  • they are prefixed with "-" for base 10.
  • if not base 10, they are returned raw in two-complement form.
Source   Edit  
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 hash(num: StUint | StInt): Hash {..}
Source   Edit  
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".}
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
Source   Edit  
template toByteArrayLE[bits: static[int]](n: StUint[bits]): array[bits div 8,
    byte] {....deprecated: "endians2.toBytesLE".}
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
Source   Edit  
template wordType(_: type SomeBigInteger): type {..}
Source   Edit