How can I change a Perl floating-point value to a bit vector?

N

none

I'd like to do bit manipulation on Perl floating-point values. Is there
any way that I can get the floating-point values into some sort of bit
vector?

Thanks,
-Mike
 
C

ctcgag

none said:
I'd like to do bit manipulation on Perl floating-point values. Is there
any way that I can get the floating-point values into some sort of bit
vector?

my @x = unpack "b*", pack "d", 1/3;

Xho
 
N

none

my @x = unpack "b*", pack "d", 1/3;

This worked perfectly! Thanks! I tried chaining pack and unpack before,
but I was assigning the result to a scalar and so didn't get the right
answer.

Thanks,
-Mike
 
C

ctcgag

none said:
This worked perfectly! Thanks!

Hold on, not so fast!
I tried chaining pack and unpack before,
but I was assigning the result to a scalar and so didn't get the right
answer.

But that is right! I was only loading the first element of @x, and that
one element is a string of ones and zeros. So I should have used a scalar
instead.

my @x=split //, unpack "b*", pack "d", 1/3;

Is what I really meant.

Xho
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top