Translating binary to English string?

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
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

Translating binary to English string?

Post by joetheeskimo5 »

I just started PHP yesterday, and I was wondering if there's a function to translate a binary string to an English string. I know there's one to translate a string to binary, but not the other way around. Please help!

Joe 8)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

I used PHP for a while... just curios: what is `binary` string? And what is `English` string? And how it differs from, say, French or Dutch strings? ;) Could you reformulate your questions, provide some examples?
joetheeskimo5
Forum Commoner
Posts: 43
Joined: Sun Dec 14, 2003 4:47 pm
Location: US
Contact:

Post by joetheeskimo5 »

Binary is a computer language, made up of 1's and 0's. An English string is a string of text in English. For example, the words I'm writing now is an English string. How can you not know that if you're a programmer?! 8O
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Computers can't hold anything but binaries, didn't you knew it? ;) So the words you wrote is stored in db in sort of binary string... There is plenty of formats, which one you call `English`? ;)

They all are made up of 1's and 0's.
Do you call `binary` C-like strings, made of ASCII representations of characters ended with zero byte? Or you're talking about Pascal string which holds its length as few first bytes? Or something else you could imagine?
Paddy
Forum Contributor
Posts: 244
Joined: Wed Jun 11, 2003 8:16 pm
Location: Hobart, Tas, Aussie
Contact:

Post by Paddy »

I don't know of a functin that does what you want but if I had your prob I would take eight characters out of the binary string at a time and then use chr to convert it from ascii to a character. You can find more info on chr here
http://au2.php.net/manual/en/function.chr.php
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

If you were to open a binary file and read in 8 characters, you'd be reading in 64 bits, and by using chr() on each of this 8 characters, you'd output the same character that you just imputted.

I think the poster needs to clarify what he means to do.

The only sensible thing I can interpret his post to mean is this.

Assume you have a text file that contains only 1's and 0's, meaning it contains strings like "01001000" or "01000010". But if this is the case, if you were to look at the binary representation of these strings, each of these strings would be made up of 64 bits of 0's and 1's. Ie, string #1 would be represented by "0011000000110001001100000011000000110001001100000011000000110000".

If this is the case, then yes, what Paddy described would be what you do.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

why not just write your own? you've already been given the values... now you just gotta write the function for it to translate it, which isn't hard at all...

the switch statement seems most logical, or a multidimensional array... up to you.
Post Reply