pack format - how do I handle int->char conversion?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CptDondo

    pack format - how do I handle int->char conversion?

    I am trying to pack a string. The data consists of an array of
    integers, something like this:

    e[1] 0x1234
    e[2] 0x0001
    e[3] 0x0002

    What I want in my resulting packed $binrow is

    0x1234 0x01 0x02

    I've tried

    pack("nCC",e[1],e[2],e[3])

    but that packs it like this:

    0x1234 0x00 0x31 0x00 0x32

    which is most definitely not what I want.

    How can I explicitly tell PHP that I want to cast an int as a char?

    (Sorry if this is a FAQ somewhere, but I can't find it... This is
    trivial to my C-trained mind but I can't see how to do it in PHP.)

    --Yan
  • CptDondo

    #2
    Re: pack format - how do I handle int->char conversion?

    CptDondo wrote:
    How can I explicitly tell PHP that I want to cast an int as a char?
    Never mind, stupid bonehead error in the code.

    --Yan

    Comment

    Working...