Packing/unpacking

J

Julie

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
 
A

Anno Siegel

Julie said:
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
 
C

Chris Mattern

Julie said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top