S
SnakeyJakey
i am trying to convert char, short in float double and long number
(they probably are currently in strings form) to binary so that i can
print out hte binary representation of each. i am currently using the
following:
$binary_int = unpack("B32", pack("I", $int));
$binary_short = unpack("b16", pack("S", $short));
$binary_char = unpack("B8", pack("C", $char));
$binary_float = unpack("b32", pack("f", $float));
$binary_double = unpack("b64", pack("d", $double));
$binary_long = unpack("b64", pack("L!", $long));
this work great for all but long. when $long can be represented in
32bit it does so but once it get larger $binary_long just saturates to
all 1's. i have tried various things in pack instead of L! like L N
etc but have not found anything that will represent a 64bit integer.
having googled about it looks like in perl they call 64bit ints quad
and they are only availiable on certain systems. im not sure if this is
thw case since in C a long is a 64bit int so this pc (x86) should be
able to support such a number.
How can i solve this.
also this prints the number from lsb to msb (a complete mirror image to
the usual little endia was of representing number msb->lsb) how can i
change this? changing from lowercase to upper case, and vise vera,
changes the endianess but still the least sig byte comes first and not
the most. is there an easy way to correct this?
many thanks
(they probably are currently in strings form) to binary so that i can
print out hte binary representation of each. i am currently using the
following:
$binary_int = unpack("B32", pack("I", $int));
$binary_short = unpack("b16", pack("S", $short));
$binary_char = unpack("B8", pack("C", $char));
$binary_float = unpack("b32", pack("f", $float));
$binary_double = unpack("b64", pack("d", $double));
$binary_long = unpack("b64", pack("L!", $long));
this work great for all but long. when $long can be represented in
32bit it does so but once it get larger $binary_long just saturates to
all 1's. i have tried various things in pack instead of L! like L N
etc but have not found anything that will represent a 64bit integer.
having googled about it looks like in perl they call 64bit ints quad
and they are only availiable on certain systems. im not sure if this is
thw case since in C a long is a 64bit int so this pc (x86) should be
able to support such a number.
How can i solve this.
also this prints the number from lsb to msb (a complete mirror image to
the usual little endia was of representing number msb->lsb) how can i
change this? changing from lowercase to upper case, and vise vera,
changes the endianess but still the least sig byte comes first and not
the most. is there an easy way to correct this?
many thanks