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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue Mar 19 02:01:28 2024 UTC