8 Einträge, 1 Seite |
use utf8;
1
2
3
4
5
0000000 # ! / b i n / p e r l lf lf m y sp
23212f62 696e2f70 65726c0a 0a6d7920
0000020 $ s sp = sp " D " ; lf p r i n t sp
2473203d 2022c422 3b0a7072 696e7420
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/local/bin/perl
use Encode qw(decode _utf8_off);
open(my $fh_8bit, ">", "utf8.txt") or die "open utf8.txt: $^E";
open(my $fh_utf8, ">", "utf8.utf") or die "open utf8.utf: $^E";
# byte order mark für UTF-8
print $fh_utf8 "\xef\xbb\xbf";
for my $num (128 .. 255) {
my $chr_8bit = chr($num);
# von 8-Bit Zeichensatz (z.B. Windows CP1252) nach UTF-8 übersetzen
my $chr_utf8 = decode("cp1252", $chr_8bit);
# wir wollen die raw octets auslesen
my $utf_octets = $chr_utf8;
_utf8_off($utf_octets);
my $raw_hex = "";
for my $byte (split(//, $utf_octets)) {
$raw_hex .= sprintf("%02x", ord($byte));
}
printf $fh_8bit ("Zeichen \\x%02x (%s) = UTF-8 \\x%s\n", $num, $chr_8bit, $raw_hex);
printf $fh_utf8 ("UTF-8 \\x%-6s = Zeichen (%s) Octets %d Chars %d\n",
$raw_hex, $utf_octets, length($utf_octets), length($chr_utf8));
}
8 Einträge, 1 Seite |