Page 1 of 1
Translating binary to English string?
Posted: Sun Dec 14, 2003 4:47 pm
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

Posted: Sun Dec 14, 2003 6:15 pm
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?
Posted: Sun Dec 14, 2003 6:40 pm
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?!

Posted: Sun Dec 14, 2003 6:54 pm
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?
Posted: Sun Dec 14, 2003 7:01 pm
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
Posted: Sun Dec 14, 2003 7:37 pm
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.
Posted: Sun Dec 14, 2003 7:37 pm
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.