Warning: include_once(/home/nullvoid/blog.mikezhang.com/wp-content/plugins/wordpress-support/wordpress-support.php): failed to open stream: Permission denied in /home/nullvoid/blog.mikezhang.com/wp-settings.php on line 217

Warning: include_once(): Failed opening '/home/nullvoid/blog.mikezhang.com/wp-content/plugins/wordpress-support/wordpress-support.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') in /home/nullvoid/blog.mikezhang.com/wp-settings.php on line 217
NullVoid » 2010 » January NullVoid » 2010 » January

Archive for January, 2010

Converting ISBN13 to ISBN10

Thursday, January 28th, 2010 -- By ET

I need to convert a bunch of isbn numbers from the 13-digit format to the 10-digit format.

Figured out the algorithm, and implemented the following subroutine in PERL.  It should be fairly simple to port it to other languages.

sub isbn1310{

my $isbn13=shift;
my @isbn13=split(//,$isbn13);

my $sum = ($isbn13[3] * 10) + (9 * $isbn13[4]) + (8 * $isbn13[5]) + (7 * $isbn13[6]) + (6 * $isbn13[7]) + (5   *   $isbn13[8]) +
(4 * $isbn13[9]) + (3 * $isbn13[10]) + (2 * $isbn13[11]);

my $mode = int(($sum / 11) + 1);
my $last = (11 * $mode) - $sum;
if ($last == 10) {
$last = "X";
} elsif ($last == 11) {
$last = 0;
}

my   $isbn10="$isbn13[3]"."$isbn13[4]"."$isbn13[5]"."$isbn13[6]"."$isbn13[7]"."$isbn13[8]"."$isbn13[9]"."$isbn13[10]"."$isbn13[11]"."$last";
return $isbn10;
}

For completeness, here is the program to convert ISBN10 back ISBN13

sub isbn1013{

my $isbn10=shift;
my @isbn10=split(//,$isbn10);

my $n = 9+7*3+8+$isbn10[0]*3 + $isbn10[1] + 3 * $isbn10[2] + $isbn10[3] + 3 * $isbn10[4] + $isbn10[5] + 3 * $isbn10[6] + $isbn10[7] + 3 * $isbn10[8];

my $n2 = $n % 10;

my $o = 10 - $n2;

my $isbn13="978"."$isbn10[0]"."$isbn10[1]"."$isbn10[2]"."$isbn10[3]"."$isbn10[4]"."$isbn10[5]"."$isbn10[6]"."$isbn10[7]"."$isbn10[8]"."$o";
return $isbn13;
}

Computing Power Skirmish

Wednesday, January 6th, 2010 -- By ET
I have to make some heavy computations these days.  It gives me a chance to compare the computing power of my two computers.
On both machines, I have the same version of MySQL.  The program, written in Perl, conducts some complex calculations based on MySQL data.
skirmish
Dell-Mac Skirmish
It is interesting to observe that my Macbook Pro actually performs better than my Dell Server.  The above figure shows 5 random sampling points, at which I count how many data records have been processed since last sampling.  Macbook constantly beats Dell.
Here are the specs:
Dell:
Dual Quad-Core Xeon CPU 2.33GHz, 32GB Memory, 1T HDD, Windows 7 64 Bit
Macbook Pro:
Core 2 Duo Intel CPU 2.8GHz, 8GB Memory, 500G HDD, Snow Leopard 64 Bit
Due to the nature of the program, only 1 CPU-Core can be used, this may explain the disadvantage of Dell. (Although it has 8 cores, 4 times that of the Macbook Pro.)
UPDATE:
A few more hours of data keep supporting the advantage of Macbook:

dellmac

Fully Utilizing My Computing Power

Tuesday, January 5th, 2010 -- By ET

Before tweaking MySQL: it used 5% of the CPU and 250MB of the memory.

After tweaking, it uses 94.3% of the CPU and 2.33GB of the memory.

I could increase the memory use even more if I needed it. :-D

screen-capture9


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2020. All rights reserved.
All trademarks property of their owners.