L
Larry.Martell
I have a situation where I have to read in 4 values from a text file,
then convert that into a float that I can use for arithmetic.
For example, the file contains "85,170,174,214" - I read this in, and
split it into an array, @d
In C, I would do something akin to this:
union convert_float32 {
float f; // float view
unsigned int i; // uint32 view
} c;
unsigned char i[4];
char *q;
for (int j=0; j<4; j++) i[j] = (unsigned char)strtoul(d[j], &q, 10);
c.i = ((unsigned int)i[0] << 24) | ((unsigned int)i[1] << 16) |
((unsigned int)i[2] << 8) | (unsigned int)i[3];
and c.f would have the value I want (in this example
23458486419456.000000)
Is there some way I can achieve the result with perl?
TIA!
-larry
How can I do a similar conversion in perl?
then convert that into a float that I can use for arithmetic.
For example, the file contains "85,170,174,214" - I read this in, and
split it into an array, @d
In C, I would do something akin to this:
union convert_float32 {
float f; // float view
unsigned int i; // uint32 view
} c;
unsigned char i[4];
char *q;
for (int j=0; j<4; j++) i[j] = (unsigned char)strtoul(d[j], &q, 10);
c.i = ((unsigned int)i[0] << 24) | ((unsigned int)i[1] << 16) |
((unsigned int)i[2] << 8) | (unsigned int)i[3];
and c.f would have the value I want (in this example
23458486419456.000000)
Is there some way I can achieve the result with perl?
TIA!
-larry
How can I do a similar conversion in perl?