note 80432 added to function.bin2hex
| From: | PHPcoder at CPE00609791e69c-CM0014e8b571b2 dot cpe dot net dot cable dot rogers dot com | Date: | Tue, 15 Jan 2008 22:11:05 +0000 |
| Subject: | note 80432 added to function.bin2hex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135125@lists.php.net to get a copy of this message | ||
Re. Matt W. and bin2hex vs. hexdec...
The compliment of bin2hex is actually pack('H*', $hex_str), where $hex_str is the ASCII
hexadecimal string (ordered high nibble first) to convert to an 8-bit (binary-safe) STRING of data.
hexdec, as explained in the documentation, converts a hexadecimal value to a decimal number. It
returns a PHP NUMERIC value, not a string!
So just a quick recap:
For STRING conversions...
... bin2hex($any_str) converts an 8-bit (binary-safe) string of data to an ASCII hex string.
... pack('H*', $hex_str) converts an ASCII hex string to an 8-bit (binary-safe) string
of data.
For NUMERIC conversions...
... hexdec($hex) converts an ASCII string representation of a number in hex to a PHP numeric
value (I'm guessing integer).
... dechex($int) converts an integer to an ASCII string representation of the value in hex.
... bindec($str) converts a string of ASCII 0's and 1's (representing a binary value)
to a PHP numeric value (I'm guessing integer).
... decbin($int) converts an integer to a string of ASCII 0's and 1's representing the
value in binary.
... octdec($str) converts an ASCII string representation of a number in octal to a PHP numeric
value (I'm guessing integer).
... decoct($int) converts an integer to an ASCII string representation of the value in octal.
And of course as every PHP programmer should know, PHP internally handles type conversion between
ASCII string representations of base-10 numbers and PHP numeric values (integer, float, etc.).
Be wary of your data types! Binary data strings are not the same as PHP numeric values!
----
Server IP: 66.207.199.35
Probable Submitter: 216.171.104.98
----
Manual Page -- http://www.php.net/manual/en/function.bin2hex.php
Edit -- https://master.php.net/note/edit/80432
Del: integrated -- https://master.php.net/note/delete/80432/integrated
Del: useless -- https://master.php.net/note/delete/80432/useless
Del: bad code -- https://master.php.net/note/delete/80432/bad+code
Del: spam -- https://master.php.net/note/delete/80432/spam
Del: non-english -- https://master.php.net/note/delete/80432/non-english
Del: in docs -- https://master.php.net/note/delete/80432/in+docs
Del: other reasons-- https://master.php.net/note/delete/80432
Reject -- https://master.php.net/note/reject/80432
Search -- https://master.php.net/manage/user-notes.php