472,354 Members | 1,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

How to save numeric value as a 32bit number rather than string?

<?
$fp = fopen ("binary.dat", "wb");
$buffer = 12345;
fwrite ($fp, $buffer);
fclose($fp);
?>

That creates a file 5 bytes long that contains the text data "12345", but I
need it to save that value as 32-bits instead (so the file would just be 4
bytes, with the contents being 0x39300000).

Anyone know how to do that?
Jul 17 '05 #1
4 1559
$someNum = 12345;

Convert to binary:
$binNum = base_convert($someNum, 10, 2);

Convert to hex:
$hexNum = base_convert($someNum, 10, 16);

http://www.php.net/manual/en/function.base-convert.php

Jul 17 '05 #2
On Wed, 27 Apr 2005 02:00:50 +0800, "Dave Turner" <no****@nowhere.nohow> wrote:
<?
$fp = fopen ("binary.dat", "wb");
$buffer = 12345;
fwrite ($fp, $buffer);
fclose($fp);
?>

That creates a file 5 bytes long that contains the text data "12345", but I
need it to save that value as 32-bits instead (so the file would just be 4
bytes, with the contents being 0x39300000).

Anyone know how to do that?


http://uk.php.net/manual/en/function.pack.php

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
Thanks, but not quite what I meant. That converts the base, but it's still a
STRING ... ie. "11000000111001"
I need to save that as just 32-bits, so the file should only be 4 bytes
"ZeldorBlat" <ze********@gmail.com> wrote in message
news:11********************@g14g2000cwa.googlegrou ps.com...
$someNum = 12345;

Convert to binary:
$binNum = base_convert($someNum, 10, 2);

Convert to hex:
$hexNum = base_convert($someNum, 10, 16);

http://www.php.net/manual/en/function.base-convert.php

Jul 17 '05 #4
pack() is the one i'm after, thanks. :)
Jul 17 '05 #5

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

Similar topics

10
by: Randell D. | last post by:
Folks, I have a box that expects numeric input - I'd like to test for it (yeah, I'll have service side checks too but also want client checks). How can I test that my input is numeric - and...
2
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005...
7
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid....
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
20
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If...
1
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image...
13
by: nishit.gupta | last post by:
Is their any fuction available in C++ that can determine that a string contains a numeric value. The value cabn be in hex, int, float. i.e. "1256" , "123.566" , "0xffff" Thnx
5
by: Mike | last post by:
I use MS SQL EXPRESS DB VS 2005, c# Win Application I have problem "The string is non-numeric" with formula CDbl({pr_DajPonudu;1.KolicinskiPopust})/100 * {@NajamProstora}
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.