Off-topic Talk Where overpaid, underworked S2000 owners waste the worst part of their days before the drive home. This forum is for general chit chat and discussions not covered by the other off-topic forums.

What does this mean?

Thread Tools
 
Old Feb 27, 2002 | 09:54 PM
  #1  
mYuuki's Avatar
Thread Starter
Banned
 
Joined: Aug 2001
Posts: 778
Likes: 0
From: Palo Alto
Default What does this mean?

#!/usr/bin/perl

print "Start Base: ";
$base = <>;
chomp $base;

print "End Base: ";
$ebase = <>;
chomp $ebase;

print "Number: ";
$bin = <>;
chomp $bin;

$bin =~ s/^0+//;
@bin = split(//, $bin);
@bin = &convert(@bin);
$dec = shift @bin;
foreach $bit(@bin){
$dec *= $base;
$dec += $bit;
}

while(($dec / $ebase) >= 1){
$result .= $dec % $ebase;
$result .= "|";
$dec /= $ebase;
use POSIX;
$dec = floor($dec);
}
$result .= $dec;
print "Base $ebase: ", &unconvert($result);

sub convert {
my @ret_arr;
foreach $bit(@_){
if($bit !~ m/d/){
$bit= uc $bit;
push @ret_arr, (ord $bit) - 55;
}
else{push @ret_arr, $bit}
}
return @ret_arr;
}

sub unconvert {
my @ret_arr;
my @temp;
@temp = split /|/, $_[0];
foreach $bit(@temp){
if($bit > 9){unshift @ret_arr, chr ($bit +55)}
else{unshift @ret_arr, $bit}
}
return @ret_arr;
}
Reply
Old Feb 27, 2002 | 10:13 PM
  #2  
mrkim019's Avatar
Registered User
20 Year Member
 
Joined: Dec 2000
Posts: 4,136
Likes: 0
From: Saratoga
Default

means you should screw perl and open up a laundromat...

Bryan
Reply
Old Feb 27, 2002 | 10:38 PM
  #3  
drogers's Avatar
Registered User
 
Joined: Jul 2001
Posts: 858
Likes: 0
From: SoCal
Default

It would appear to convert numbers from one base to another. It should prompt you for a Start Base which would be - duhh - the base you're starting with, and end base, which is what you want to convert to, and a number to convert. So if you put in 10 for start base, 2 for end base, and 16 for the number, your result would be 10000, which is equivalent to 16 in binary, or base 2...

Actually, it's appears to be a pretty handy little script!
Reply
Old Mar 11, 2002 | 04:19 PM
  #4  
jprivara's Avatar
Registered User
 
Joined: Mar 2002
Posts: 210
Likes: 0
From: Sacramento
Default

Where did it come from?

$ ./bozo
Start Base: 10
End Base: 17
Number: 16
Base 17: G
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Communist_StooK
Off-topic Talk
18
Jun 9, 2008 06:07 PM




All times are GMT -8. The time now is 10:29 AM.