ok, this is driving me nuts. i have a string in perl. let's call it $s.
now i want to take $s 6 bits at a time and put each 6 bits (plus 32) into
a byte in $e. in other words each 3 bytes of $s become 4 bytes in $e.
anyone else play with bit shifting in perl? it doesn't seem to be
working so far.
this doesn't work and i feel like shooting it at this point:
#!/usr/bin/perl
$s = shift;
$s .= "\0" x ((length($s) % 3)? 3 - (length($s) % 3): 0);
$e = "";
while (length($s) > 0) {
$c = substr($s, 0, 3);
$s = substr($s, 3);
foreach $x (1...4){
$e .= chr((ord(substr($c, 0, 1)) & 0xfc) + 32);
$c <<= 6;
}
}
$d = "";
print("original: $s(".length($s).")\nencoded: $e\ndecoded: $d\n");
kevin
--
kevin at suberic.net buffy: come on, can't you put your foot down?!
fork()'ed on 37058400 giles: it *is* down.
meatspace place: orbit buffy: one of these days you're going to have to
http://suberic.net/~kevin get a grown up car. --inca mummy girl
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!