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]), toHex(b[3])]
and not sure what the byte order should be
