Binary representation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
per2008
Forum Newbie
Posts: 1
Joined: Fri Jun 27, 2008 6:54 am

Binary representation

Post by per2008 »

Hi!

I have a question regarding type conversion and memory storage. I've looked around after functions for appropriate conversion, but haven't found any yet.

What I'm tring to do is to convert double, int and strings to binary format. Or more pricesely to the format used to store these types in memory. In C++/Java this is known as the byte-type. For instance, a int would be stores as four consequtive bytes in memory.

I'm found diverse functions like decbin(...), base_convert(...), pack(...), etc., but no functions that can help. So, to precisely define the problems:

- Coversion of a int to a byte array (4 bytes, little endian)
- Coversion of a double to a byte array (8 bytes, little endian)
- Conversion of a string to a byte array (x bytes)
- Write these the contents of these arrays to file (binary files)

Does anyone has any suggestions on how this may be done? Really appreciated!
Post Reply