Page 1 of 1
How to convert a hex or decimal to base64
Posted: Tue Jul 27, 2004 4:58 pm
by WaldoMonster
I know the base64_encode command but it is for binary data.
And base_convert is limited to base 36.
Any help will be appreciated.
Posted: Tue Jul 27, 2004 6:37 pm
by kettle_drum
Everything is always for binary. Hex and decimal characters are still binary. You can use base64_encode() for anything.
Posted: Wed Jul 28, 2004 3:42 am
by WaldoMonster
I mend a number transformation.
The same way you can convert a decimal to hex with $hex = baseconvert($dec, 10, 16);
11 decimal = a base64
62 decimal = Z base64
Posted: Wed Jul 28, 2004 11:16 am
by hedge
I don't think base64_encode is what you want. Base 64 encoding is used for converting binary data to string such as putting attachments in email, It doesn't do number system conversions.
You'd have to write your own function to do that conversion just curious but what characters are used for base64? upper and lowercase maybe?
Posted: Wed Jul 28, 2004 11:42 am
by feyd
a-zA-Z0-9 and a few symbols..
to find out the exact ones:
Code: Select all
<?php
$stream = '';
for($x = 0; $x < 64; $x++) $stream .= chr($x);
echo base64_encode($stream);
?>
Posted: Wed Jul 28, 2004 7:42 pm
by kettle_drum
Its:
26 - lowercase letters
26 - uppercase letters
10 - numbers
2 - + and /
64 values - hense the name.
Posted: Sun Jan 29, 2006 10:27 am
by WaldoMonster
This is what I use now to convert
hex to
base64:
Code: Select all
$base64 = base64_encode(pack('H*', $hex));