[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Solved: [OT] Perl und hohe Mathematik!?



Hallo,

Am Don, 13 Mai 2010, Thomas Halinka schrieb:
>Am Donnerstag, den 13.05.2010, 14:00 +0200 schrieb Thomas Halinka:
[..]
>        use Math::BigInt;
>        
>        my $hex = '95 93 E4 4A 66 46 E1 00';
>        $hex =~ s/ //g; # spaces entfernen
>        $hex = '0x'.$hex; # hex zahlen sind mit 0x prefixed
>        
>        my $big_int = new Math::BigInt($hex);
>        print $big_int, "\n";
>
># perl /home/thohal/convert.pl
>10778209341422362880
>
>Nun etwas schoen machen.....

Is aber falschrum.

====
#!/usr/bin/perl -w
use strict;
use POSIX qw(strftime locale_h);
use Math::BigInt try => 'GMP';
setlocale(LC_TIME, 'de_DE');

my @dates = (
             "95 93 E4 4A 66 46 E1 00",
             "22 16 30 DC 66 46 E1 00",
             "74 1A AD C9 66 46 E1 00"
);

my $epoch = Math::BigInt->new("0x00dcbffeff2bc000");

foreach(@dates) {
  my $t = Math::BigInt->new("0x" . join("",reverse(split(/\s+/))));
  $t->bsub($epoch);
  print strftime("%c", gmtime($t)), "\n";
}
====

Evtl. nicht die schnellste Variante, aber "einfach" ;)

-dnh

-- 
(Multiple bracketed paragraphs usually indicate a severe lack of focus.)
                                                   -- Juliusz Chroboczek


Reply to: