What is the best way to do this in Nim?
There is http://nim-lang.org/docs/endians.html
import endians
let b = "\xff\x0\x0\x0"
var a: uint32
swapEndian32(addr(a), unsafeAddr(b[0]))
echo a
let c: uint32 = 0xff000000u32
swapEndian32(addr(a), unsafeAddr(c))
echo a
I use unsafeAddr() here but with vars you can use addr().