I am currently working with UDP packets and I need to craft and send custom data. Because it is easier for me to read I work with strings representing hexadecimal values. I have something like this :
a = "12"
b = "15"
header = "c56b4040003300" + a + "800401" + b + "90000000"
Now, what I want to do is converting my header variable into hexadecimal (but not with the hexadecimal value of every character in header). It means that if I write my header variable in a file and I open it with a hexadecimal editor, I want to see
c5 6b 40 40 00 33 00 12 80 04 01 15 90 00 00 00
I don't have a good knowledge of ruby and I couldn't find a way to do it so far. The pack function converts characters in hexa but not hexadecimal string representation as hexadecimal value. And doing something like
header = "\xc5\x6b\x40\x40\x00\x33\x00\x" + a + "\x80\x04\x01\x" + b + "\x90\x00\x00\x00"
will throw me an error saying "invalid hex escape" (which make sense). So if you have a solution to this problem please tell me (if possible without using any external library)