Page 1 of 1

Unexpected output with pack()

Posted: Sun May 18, 2008 10:47 pm
by EricS
I'm trying to pack a hex string into binary but I'm not getting the output I expect:

Code: Select all

var_dump(bin2hex(pack('H', 'ff')));
Returns

Code: Select all

string(2) "f0"
But shouldn't it be returning

Code: Select all

string(2) "ff"
Thank you in advance.

Re: Unexpected output with pack()

Posted: Mon May 19, 2008 2:27 am
by Chris Corbyn
Actually that's correct.

H tells it to only read the first byte in the input string (F).

H* is what you need (FF).