Re: Help with Unicode decompiling problem

From: John Cowan (cowan@ccil.org)
Date: Thu Nov 04 1999 - 12:06:08 EST


Ben Yenko-Martinka wrote:

> Thank you John, but don't you have your shift operators confused?

Of course I do: a brain fart.

> Of course, if I add & 0xF for the high nibble also it wouldn't matter.

That is clearly the most robust strategy, and I scarcely believe that the
run-time cost will be noticeable. So:

    private static final char[] hex = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                                       'A', 'B', 'C', 'D', 'E', 'F'};
    private static char[] hexBuffer = {'\\', 'u', '0', '0', '0', '0'};
    public String hexRep(char c)
      {
      hexBuffer[2] = hex[(c >> 12) & 0xF];
      hexBuffer[3] = hex[(c >> 8) & 0xF];
      hexBuffer[4] = hex[(c >> 4) & 0xF];
      hexBuffer[5] = hex[c & 0xF];
      return new String(hexBuffer);
      }

-- 

John Cowan http://www.reutershealth.com jcowan@reutershealth.com Schlingt dreifach einen Kreis vom dies! / Schliess eurer Aug vor heiliger Schau Den er genoss vom Honig-Tau / Und trank die Milch vom Paradies. -- Coleridge (tr. Politzer)



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:54 EDT