Just as the title suggests, what is the recommended way of converting a 
sequence of four uint8's into a uint32? Or even more specifically, how would 
you convert four consecutive bytes within a larger sequence into a uint32? At 
the moment, I'm doing this:
    
    
    var offset = 0
    var x = (cast[int32](buf[offset]) shl 0) or
            (cast[int32](buf[offset+1]) shl 8) or
            (cast[int32](buf[offset+2]) shl 16) or
            (cast[int32](buf[offset+3]) shl 24)
    

but this doesn't seem particularly efficient since it involves four individual 
casts and bit ops. Any suggestions? Thanks.

Reply via email to