Re: urban legends just won't go away!

2003-01-31 Thread Eric Muller


Barry Caplan wrote:


Who knew in this day and age flipping bits to change case is still publishable (this is from today!)
 

What I find a lot more objectionable is that what this code pretends to 
do is not defined (in particular, the domain over which it applies). 
Without such qualification, we cannot say if the code is correct or not, 
no matter how fishy it looks. In fact, this example is a perfectly valid 
implementation if the system pretends to handle only an appropriate 
subset of the Unicode character set.

For more information, see .

Eric.





Re: urban legends just won't go away!

2003-01-30 Thread Kenneth Whistler

> This is a simple example demonstrating my own personal method.
> 

//to upper case
  public char upper(int c)
  {
return (char)((c >= 97 && c <=122) ?  VisitSewers(c) : c);
  }

  static int VisitSewers(int c)
  {
return AlligatorByte(c);
  }
  
  static int AlligatorByte(int c)
  {
// Remove SPACE from character and return mangled remnant.
return (c - 0x20); 
  }
  
  





RE: urban legends just won't go away!

2003-01-30 Thread Carl W. Brown
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Barry Caplan
> Sent: Wednesday, January 29, 2003 10:01 PM
> To: [EMAIL PROTECTED]
> 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  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"));
> }
>
>
>