From: Carl W. Brown (cbrown@xnetinc.com)
Date: Thu Jan 30 2003 - 11:36:34 EST
Barry,
If you think that this is bad try 390 mainframe EBCDIC shift to upper case.
You can shift up to 256 characters at a time with a single machine language
instruction by ORing a line of spaces to your character field. Now that is
bit flipping and is still heavily used.
Carl
> -----Original Message-----
> From: unicode-bounce@unicode.org [mailto:unicode-bounce@unicode.org]On
> Behalf Of Barry Caplan
> Sent: Wednesday, January 29, 2003 10:01 PM
> To: unicode@unicode.org
> Subject: urban legends just won't go away!
>
>
> http://archive.devx.com/free/tips/tipview.asp?content_id=4151
>
> Who knew in this day and age flipping bits to change case is
> still publishable (this is from today!)
>
> Barry Caplan
> www.i18n.com
> Vendor Showcase: http://Showcase.i18n.com
>
>
> --------------------------------------------------------------
>
> Use Logical Bit Operations to Changing Character Case
>
>
> This is a simple example demonstrating my own personal method.
>
> // to lower case
> public char lower(int c)
> {
> return (char)((c >= 65 && c <= 90) ? c |= 0x20 : c);
> }
>
> //to upper case
> public char upper(int c)
> {
> return (char)((c >= 97 && c <=122) ? c ^= 0x20 : c);
> }
> /*
> If I would I could create a method for converting an entire
> string to lower, like this:
> */
> public String getLowerString(String s)
> {
> char[] c = s.toCharArray();
> char[] cres = new char[s.length()];
> for(int i=0;i<c.length;++i)
> cres[i] = lower(c[i]);
> return String.valueOf(cres);
> }
> /*
> even converting in capital:
> */
> public String capital(String s)
> {
> return
> String.valueOf(upper(s.toCharArray()[0])).concat(s.substring(1));
> }
> /* using it....*/
> public static void main(String args[])
> {
> x xx = new x();
> System.out.println(xx.getLowerString("LOWER: " + "FRAME"));
> System.out.println(xx.upper('f'));
> System.out.println(xx.capital("randomaccessfile"));
> }
>
>
>
This archive was generated by hypermail 2.1.5 : Thu Jan 30 2003 - 12:32:29 EST