in reply to Re: UCS2/HexEncoded
in thread UCS2/HexEncoded

Hi, what if a char is greater than FF (i.e. unicode), than shouldn't it be 0100, 0101, etc? In that case you would need to make the following change to L~R's code:

print UCS2( 'Hello' ); sub UCS2 { return join '', map { sprintf("%02X",ord) } split //, $_[0] + }

The only change is in the sprintf format.

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Replies are listed 'Best First'.
Re^3: UCS2/HexEncoded
by Limbic~Region (Chancellor) on Feb 17, 2005 at 20:42 UTC
    TedYoung,
    I thought about that but wasn't sure what UCS2 was or what ranges were valid. Too bad the question wasn't asked better. Incidently, the process can be reversed:
    sub decode { return join '', map { chr( hex ) } unpack( 'A4' x (length +($_[0]) / 4), $_[0] ) }

    Cheers - L~R