my $unicode_character_hexadecimal_string = '0x20ac';
It would be easier/better to leave off the quotes -- this way, you don't need to use eval later on:
From here, I want to get to some hexadecimal string representation of the UTF-8 encoding of this Unicode codepoint:my $unicode_hex_codepoint = 0x20ac;
'0xE2 0x82 0xAC'
I don't understand why you would want to do that. Normally, you want to go directly to a perl-internal utf8 character:
Then, as strange as it seems, I want to get to an analagous hexadecimal string representation of the same sequence of bytes with the most significant bit turned off (i.e, with 0x80 substracted):my $unicode_char = chr( $unicode_hex_codepoint );
'0x62 0x02 0x2C'
You're right. That does seem very strange. I'll be losing sleep trying to imagine what sort of purpose this could possibly serve. In any case, if your ultimate goal is a print-out that looks something like this (I'm just guessing about the format):
€ == 20ac == e2 82 ac == 11100010 10000010 10101100 ^^ 62 02 2c == 01100010 00000010 00101100Then something like this, perhaps:
There are other ways to do it, which might be more suitable, depending on why you really want to do this (and what sorts of data you'll be dealing with).use strict; my $uni_hex = 0x20ac; my $uni_chr = chr($uni_hex); my ( $u8_byts, $strpd_byts ); $u8_byts .= sprintf( "%02x ", $_) for ( unpack( "C*", $uni_chr )); $strpd_byts .= sprintf( "%02x ", $_ & 0x7f ) for ( unpack( "C*", $uni_ +chr )); ( my $u8_bits = unpack( "B*", $uni_chr )) =~ s/(.{8})/$1 /g; ( my $strpd_bits = $u8_bits ) =~ s/\b1/0/g; printf( "%s == %04x == %s == %s ^^ %s == %s\n", $uni_chr, $uni_hex, $u8_byts, $u8_bits, $strpd_byts, $strpd_bi +ts );
In reply to Re: Need Help With Seemingly Bizarre Unicode Task
by graff
in thread Need Help With Seemingly Bizarre Unicode Task
by Jim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |