#!/usr/bin/perl # ucs2toutf8.pl - Don Yang (uguu.org) # # Convert UCS-2BE bytes to UTF-8. # # 02/18/07 use strict; while(my $c = <>) { $c =~ s/\s//gs; $c = hex($c); if( $c <= 0x7f ) { printf '%02x %02x -> %02x'."\n", ($c >> 8), ($c & 255), $c; } elsif( $c <= 0x7ff ) { printf '%02x %02x -> %02x %02x'."\n", ($c >> 8), ($c & 255), (0xc0 | ($c >> 6)), (0x80 | ($c & 0x3f)); } elsif( $c <= 0xffff ) { printf '%02x %02x -> %02x %02x %02x'."\n", ($c >> 8), ($c & 255), (0xe0 | ($c >> 12)), (0x80 | (($c >> 6) & 0x3f)), (0x80 | ($c & 0x3f)); } elsif( $c <= 0x10ffff ) { printf '%02x %02x -> %02x %02x %02x %02x'."\n", ($c >> 8), ($c & 255), (0xf0 | ($c >> 18)), (0x80 | (($c >> 12) & 0x3f)), (0x80 | (($c >> 6) & 0x3f)), (0x80 | ($c & 0x3f)); } }