Jump to content

  • Log In with Google      Sign In   
  • Create Account

[web] unpack: Binary string to hex string (PHP)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BeanDog   Members   -  Reputation: 1063

Like
0Likes
Like

Posted 18 November 2005 - 04:52 AM

I'm trying to use the unpack function in PHP to convert a text or binary string to its hexadecimal representation (e.g. 'hello' -> '68656c6c6f')
function _hexstring($bin)
{
	list(,$ret) = unpack('h1', $bin);
	return($ret);
}
I'm missing something fundamental here. It returns a blank string. Anybody have an idea? ~BenDilts( void );

Sponsor:

#2 konForce   Members   -  Reputation: 588

Like
0Likes
Like

Posted 18 November 2005 - 07:33 AM

Try:


function _hexstring($bin)
{
list(,$ret) = unpack('H'.strlen($bin)*2, $bin);
return($ret);
}



#3 BeanDog   Members   -  Reputation: 1063

Like
0Likes
Like

Posted 18 November 2005 - 07:54 AM


function _hexstring($bin)
{
list(,$ret) = unpack('h*1', $bin);
return($ret);
}

Solved.

Thanks, you pointed me in the right direction!



~BenDilts( void );




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS