Convert bytes of numerics to character arrays


#1

In C, I might memcpy an int or short into an array of characters. Is
there some wonderful way in Ruby to append the bytes which compose a
numeric value to a character array? This is useful for things like
constructing fixed-length field packets. Thank you.


(Niklas Frykholm) #2

[Brian]:

In C, I might memcpy an int or short into an array of characters. Is
there some wonderful way in Ruby to append the bytes which compose a
numeric value to a character array? This is useful for things like
constructing fixed-length field packets. Thank you.

Look at the #pack and #unpack functions.

// Niklas