you could use unpack instead of hex; pack is definitly wrong. remember: hex is a string (representation) of an (integer) value.
pack creates a (one) string out of (multiple) values.
unpack creates (multiple) values out of a (one) string.
Therefore it is better to wrap the var in () in a call to unpack.