473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Turn binary number 0xFFFFFFEE into a float?

I have a binary file which only has 4 bytes "FFFFFFEE". I just want to
put it in a variable equaling 4294967278.
How I've failed so far:

<?

$foo= bin2hex(file_get_contents('testplz.bin'));

// This correctly creates the hex number but on closer inspection it
just turned it into a string.

$foo=intval(bin2hex(file_get_contents('testplz.bin ')),16);

// This works up until the value exceeds 2147483647, there's a
function called floatval but it doesn't accept the ,16 argument and
doesn't accept binary either

settype($foo, "float");

// Any variation of bin2hex, casting, etc don't seem to give me a
correct answer

echo (float)bin2hex(file_get_contents('testplz.bin'));

?>
Please help ='/, I can't proceed with what I need to finish.
Jul 18 '08 #1
3 2652
"JimmyR.com" wrote:
>
I have a binary file which only has 4 bytes "FFFFFFEE". I just want to
put it in a variable equaling 4294967278.

How I've failed so far:

<?

$foo= bin2hex(file_get_contents('testplz.bin'));
[...]
// Any variation of bin2hex, casting, etc don't seem to give me a
correct answer

echo (float)bin2hex(file_get_contents('testplz.bin'));

?>

Please help ='/, I can't proceed with what I need to finish.
$foo= hexdec(file_get_contents('testplz.bin')); should do the trick.

Bye!
Jul 18 '08 #2
it returns 0
Jul 18 '08 #3
Thanks for all the detail but the first thing I said was its a binary
file. It's not FFFFFFEE ASCII. Someone else helped me figure it out
though, here's a function I made

function b2f($val) return floatval(hexdec(bin2hex($val)));

echo b2f(file_get_contents('testplz.bin'));
Jul 19 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mariusz Sakowski | last post by:
I'm writing class which will be able to store large numbers (my ambition is to make it able to operand on thousands of bits) and perform various operations on it (similiar to those available with...
7
by: laclac01 | last post by:
So I am converting some matlab code to C++. I am stuck at one part of the code. The matlab code uses fread() to read in to a vector a file. It's a binary file. The vector is made up of floats,...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
25
by: Gaurav Verma | last post by:
Hi, I want to convert a floating point number (or a decimal number say 123.456) into binary notation using a C program. Can somebody help me out with it? Thanks Gaurav --...
10
by: 63q2o4i02 | last post by:
Hi, I'm using python to run some lab equipment using PyVisa. When I read a list of values from the equipment, one of the fields is 32 bits of flags, but the value is returned as a floating...
9
by: gamehack | last post by:
Hi all, I've been wondering when I write a structure like: struct { int a; unsigned int b; float c; } mystruct;
8
by: Ronin | last post by:
I'm very new to C++ coming in from using C# and the like. I've read a lot of good posts about binary files but I'm still missing a few key ingredients that will help me with the following problem....
2
by: bilbo2000 | last post by:
I am trying to read in a binary file which has the data stored as 32 bit float. I have been trying to figure out how to read this in as 32 bit but everytime I try to read it in the best I can do...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.