Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Packing/unpacking

Reply
Thread Tools

Packing/unpacking

 
 
Julie
Guest
Posts: n/a
 
      09-22-2003
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
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      09-22-2003
Julie <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Chris Mattern
Guest
Posts: n/a
 
      09-22-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments