Skip to content

Instantly share code, notes, and snippets.

@mratsim
Created April 19, 2018 12:34
Show Gist options
  • Save mratsim/b3b3ccf96fae413fc2fdaccb64d8d759 to your computer and use it in GitHub Desktop.
Save mratsim/b3b3ccf96fae413fc2fdaccb64d8d759 to your computer and use it in GitHub Desktop.
func tohexBE[T: uint8 or uint16 or uint32 or uint64](x: T): string =
let bytes = cast[array[T.sizeof, byte]](x)
result = ""
for i in countdown(T.sizeof - 1, 0):
result.add toHex(bytes[i])
func tohexBE(x: MpUintImpl): string =
const size = size_mpuintimpl(x) div 8
let bytes = cast[array[size, byte]](x)
result = ""
for i in countdown(size - 1, 0):
result.add toHex(bytes[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment