文字と文字コード

                             <p>ソースコード</p>
  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/perl

#BEGIN{
#   print "Content-type: text/plainnn";
#   open(STDERR, ">&amp;STDOUT");
#   $|=1;
#}

$usr_title = 'テスト32';

$tgCode = ord('漢');
if($tgCode == 0x8a){
    $usr_outcode = 'sjis';
}elsif($tgCode == 0xb4){
    $usr_outcode = 'euc';
}

require "./tsenv.pl";

{
    printHeader($usr_title);
    printBodyHeader('文字←→文字コード');

# チェックする文字
    @checkStrs = ('a', 'A', '1', '@', '\', '}', '[ ]', 'あ');

# 1文字変換
    Jprint(<<EOM);
<table border=1>
<caption>ord() &amp;amp; chr()</caption>
<tr>
<th rowspan=2>文字
<th rowspan=2>→
<th colspan=5>文字コード
<th rowspan=2>→
<th rowspan=2>文字
</tr>

<tr>
<th>10進数
<th>→
<th>16進数
<th>→
<th>10進数
</tr>

EOM

    foreach(@checkStrs){
        my $dOrd  = ord();
        my $hOrd  = sprintf("%x", $dOrd);
        my $dhOrd = hex($hOrd);
        my $dChr  = chr($dhOrd);
        print <<EOM;
<tr>
<td>$_
<td>
<td>$dOrd
<td>
<td>$hOrd
<td>
<td>$dhOrd
<td>
<td>$dChr
</tr>

EOM

    }

    Jprint(<<EOM);
</table>
EOM

# 一括変換その2
    push @checkStrs, '漢字', 'Nobu3', '!"#()=~';

    Jprint(<<EOM);
<table border=1>
<caption>unpack(H*) &amp;amp; pack(H*)</caption>
<tr>
<th>文字
<th>→
<th>文字コード
<th>→
<th>文字
</tr>

EOM

    foreach(@checkStrs){
        my $hunpack = unpack("H*", $_);
        my $hpack = pack("H*", $hunpack);
        print <<EOM;
<tr>
<td>$_
<td>
<td>$hunpack
<td>
<td>$hpack
</tr>
EOM

    }

    Jprint(<<EOM);
</table>
EOM

    printFooter();

    exit(0);
}
                          </div>
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy