php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9168 unpack 'h' and 'H' formats don't work
Submitted: 2001-02-07 18:56 UTC Modified: 2001-03-20 05:45 UTC
From: rusty at socrates dot berkeley dot edu Assigned:
Status: Closed Package: Strings related
PHP Version: 4.0.4pl1 OS: solaris 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rusty at socrates dot berkeley dot edu
New email:
PHP Version: OS:

 

 [2001-02-07 18:56 UTC] rusty at socrates dot berkeley dot edu
In the following sample the variable "encoded" is zero length; an empty string.  If I change the format chars from H and h to C then it does get stuff.

<script language="php">

// 0xFF * 0xEE
$ch = 60690;

$encoded = "";

$hexn = unpack("Hz", $ch); // high nibble
if (isset($hexn["z"]))
  $encoded .= $hexn["z"];
else
  $encoded .= "-";

$hexn = unpack("hz", $ch); // low nibble
if (isset($hexn["z"]))
  $encoded .= $hexn["z"];
else
  $encoded .= "-";

echo $encoded . "<br>";
echo strlen($encoded) . "<br>";

</script>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-20 05:45 UTC] stas@php.net
H and h doesn't work by nibbles, only by bytes (i.e., you
cannot really do unpack("H<n>z") when n is not even.
Otherwise, if you write unpack("Hz/C"), the C whould have to
start from half-byte, which is absurd.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC