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 = 123.45
      s = @[1, 2, 3, 4]
      t: tuple[a: int, b: string] = (1, "123")
      set: set[uint8] = {1'u8..3'u8, 5'u8..6'u8}
      a: array[5, uint8] = [1'u8, 2, 3, 4, 5]
    
    echo i.hexDump
    echo ui.hexDump
    echo f.hexDump
    echo s.hexDump
    echo t.hexDump
    echo set.hexDump
    echo a.hexDump
    

Reply via email to