Packing/unpacking

Discussion in 'Perl Misc' started by Julie, Sep 22, 2003.

  1. Julie

    Julie Guest

    I am trying to take a number 64001072 and get this value into a 3-byte binary value.

    I have tried:

    $val = 640001072;
    $value = pack("l",$val);
    ($s1, $s2, $s3, $s4) = unpack("CCCC",$value);
    $new_value = pack("CCC",$s3,$s2,$s1);

    this works for other values, but does not seem to work for this value.

    Any suggestions???

    Thanks,
    Julie
    Julie, Sep 22, 2003
    #1
    1. Advertising

  2. Julie

    Anno Siegel Guest

    Julie <> wrote in comp.lang.perl.misc:
    > I am trying to take a number 64001072 and get this value into a 3-byte
    > binary value.
    >
    > I have tried:
    >
    > $val = 640001072;
    > $value = pack("l",$val);
    > ($s1, $s2, $s3, $s4) = unpack("CCCC",$value);
    > $new_value = pack("CCC",$s3,$s2,$s1);
    >
    > this works for other values, but does not seem to work for this value.
    >
    > Any suggestions???


    No. 64001072 > 2**24. It won't fit into three bytes, whichever way you
    turn it.

    Anno
    Anno Siegel, Sep 22, 2003
    #2
    1. Advertising

  3. Julie wrote:
    > I am trying to take a number 64001072 and get this value into a 3-byte binary value.
    >

    Well, that'll be a neat trick if you can manage it.

    The number requires four bytes to hold it.

    Chris Mattern
    Chris Mattern, Sep 22, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor S. Miller

    Packing and unpacking bitvectors

    Victor S. Miller, Oct 9, 2003, in forum: Python
    Replies:
    0
    Views:
    289
    Victor S. Miller
    Oct 9, 2003
  2. Eelco
    Replies:
    121
    Views:
    1,705
    Eelco
    Jan 3, 2012
  3. Lucas L.
    Replies:
    12
    Views:
    192
    ara.t.howard
    Jun 16, 2008
  4. Aaron D. Gifford
    Replies:
    3
    Views:
    175
    Aaron D. Gifford
    Apr 7, 2011
  5. Shashank R Khanvilkar

    Packing/Unpacking bit fields from a byte.

    Shashank R Khanvilkar, Sep 25, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    407
    Anno Siegel
    Sep 26, 2005
Loading...

Share This Page