in reply to Convert to Hexadecimal

Hex is text. «2 hex bytes» makes no sense. You actually want «2 bytes equal to "\x00\x0C"», and that's obtained using
pack('n', length($string))

You might also be interested in the following:

pack('n/a*', $string)

It's short for

pack('n', length($string)) . $string