«

»

Apr
25

Hexadezimal in Dezimal

Folgendes Perl-Script konvertiert alle Hexadezimalen Zahlen (0x…) der Standardeingabe (stdin) in Dezimale Zahlen und gibt es auf der Standardausgabe (stdout) aus:

#!/usr/bin/perl -lw

use strict;

while (<>) {
        chomp;
        s/0[xX]([a-fA-F0-9]+)/sprintf('%d', hex('0x'.$1))/eg;
        print $_;
}

Benutzung in etwa wie folgt:

perl hex_2_dec.pl < hex.txt > dec.txt

“hex.txt” enthält beispielsweise folgende Zeile:

#define CSIDL_DESKTOP                   0x0000        // 

“dec.txt” enthält folgende Zeile:

#define CSIDL_DESKTOP                   0        // 

Hinterlasse eine Antwort

Ihre E-Mail-Adresse wird nicht veröffentlicht.

Sie können diese HTML-Tags verwenden: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

What is 3 + 2 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)