Re: bytes to hex string

2017-11-15 Thread federico3
There's an open PR for this: [https://github.com/nim-lang/Nim/pull/6517](https://github.com/nim-lang/Nim/pull/6517)

Re: bytes to hex string

2017-11-15 Thread random898989
Thanks @jlp765 and @dataman. I decided to go with the following for now. proc guid():string= result = "" const l = 8 let f = open("/dev/urandom") var a:array[l, byte] discard readBytes(f, a, 0, l) close(f) for b in a: result.add(

Re: bytes to hex string

2017-11-14 Thread dataman
import strutils proc hexDump*[T](v: T): string = var s: seq[uint8] = @[] s.setLen(v.sizeof) copymem(addr(s[0]), v.unsafeAddr, v.sizeof) result = "" for i in s: result.add(i.toHex) var i: int64 = 123 ui: uint64 = 123 f: float = 1

Re: bytes to hex string

2017-11-13 Thread jlp765
Have a look at `toHex()` in strutils which for anything bigger than a byte, you can specify the number of Hex chars to produce, and for a byte will output two hex chars. so maybe as the equivalent of one of your %x try (untested) "$1$2$3$4" % [toHex(b[0]), toHex(b[1]), toHex(b[2]),

bytes to hex string

2017-11-13 Thread random898989
Ok this is embarrassing but what's Nim's equivalent of printf? In particular stringifying a bunch of bytes as a hex string? I see a format proc in strutils but it seems to only accept string varargs. I was trying to put together a crude guid generation function I have in Golang (see below) but I