Perl

Converting a Hex String to an Array of Bytes
When parsing messages, it's often easier to work with an array of bytes rather than using substr() to fetch individual nibbles from a hex string. Here's one way to do it:
#
# first, create an array containing an
# element for each pair of hex bytes
#
@pdu = unpack "a2" x (length()/2), $_;

#
# now, turn those pairs into binary data
#
map $_ = hex ($_), @pdu;