tags:

views:

79

answers:

1

I remember there was a function in PHP where you can choose how many bits each character of a string represents (I dont remember if it was for converting string or for generating them).
For example if you chose 4 bits per caracter then the output string would be formed by hexadecimal characters only (0-9 A-F). If you chose 5 bits per caracter then the output string will include more characters (not just hexadecimal ones) since the alphabet needs to have 32 characters (2^5); and if you chose 6 bits per charaters then an alphabet of 2^6=64 characters was used.
Of course, the more bits per character you choose, the shorter the output string will be.

Does anyone know what I'm talking about?? I'm quite sure there was a built-in function for this in PHP, but I cant find it.

+1  A: 

Are you looking for base_convert(), perhaps?

ChssPly76
+1 yes I believe he is.
Josh
No, that's not the one. Now I start to remember that the fuction was a hash generator, and you could choose the size of the alphabet to use (either 16, 32 or 64 characters -- i.e. 4, 5 or 6 bits per character).But I'm beginning to think that it was on another language (may be Java?).
Generating hashes has nothing to do with encoding. You're talking about transforming byte array into a string taking X bits at a time. In java you'd use `Integer.toString(value, radix)` to do that, PHP's alternative is `base_convert()`. In both cases you'll need to do some bit manipulation to split source byte array into tokens X bits long. PHP has ready made implementations for X=4 - `bin2hex()` and X=6 - `base64_encode()`.
ChssPly76