These days I don’t think that I’d
be doing bitwise operation unless I were writing a routine for machine language
or working with a very ancient and limited subset language (hmmm̷0;come to
think of it, I do!)
Modern languages have functions like LCASE
and UCASE that you can use to convert the case of your characters. (It might be
interesting to use Ildasm.exe to take a peek at the intermediate language (MSIL)
that VB generates and see what exactly they do to implement LCASE and UCASE.)
If you want to do a bit more coding, you
could determine the ASCII value of the character (ASC) and test for upper or
lower case (upper case >=41h and <=5Ah, lower case >=61h and <=7Ah)
and then either add 20h to the upper case
to get lower and subtract 20h from the lower case to get to upper.
/tr
From: helpwithvb
yahoogroups.com [mailto:helpwithvb
yahoogroups.com] On Behalf Of John Smithman
Sent: Monday, March 03, 2008 12:41
PM
To: helpwithvb
yahoogroups.com
Subject: RE: [helpwithvb] Re:
Logical OR as mask for changing case
Thanks tr.
I haven't tried it yet; but I
think your XOR operation works to change the case in both directions.
It's like a flip switch or logical NOT.
Is there a way to apply a mask that will
put it UPPER case no matter what case it starts as?
And one that puts it into lower
case no matter what case it starts out as?
John Smithman
From: helpwithvb
yahoogroups.com [mailto:helpwithvb
yahoogroups.com] On Behalf Of Tim Rupp
Sent: Monday, March 03, 2008 3:13
AM
To: helpwithvb
yahoogroups.com
Subject: RE: [helpwithvb] Re:
Logical OR as mask for changing case
That’;s certainly one way you could do it.
You could also apply a bit mask of 1101 111, which is DF in
hex, and by using the AND function get the same result.
Seems there̵7;s always more than one way to get to where
we want to go with this stuff!
/tr
From: helpwithvb
yahoogroups.com
[mailto:helpwithvb
yahoogroups.com]
On Behalf Of John Smithman
Sent: Monday, March 03, 2008 12:44
AM
To: helpwithvb
yahoogroups.com
Subject: [helpwithvb] Re: Logical
OR as mask for changing case
Thanks
Tim. John Smiley told me you would have the answer.
So, then when converting to UPPER case we use XOR 20h; but when
converting to lower case, we use char(<LETTER>) OR 20h. Is that so?
John
--- In helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com,
"Tim Rupp" <tim.rupp
...> wrote:
>
> Ok. I don't know how much explanation is required so I'll give you
the whole
> enchilada.if you don't need it all just take what is required for
you. ;) I
> want to make it 54h using one of our logic functions.
>
>
>
> 0111 0100 = 74h
>
> ???? ????
>
> 0101 0100 = 54h
>
>
>
> What we want is to make sure that the second bit of the upper four
bit
> nibble is zero instead of one, yet we don't want to change any
other bit.
> Interestingly enough, 20h is expressed in binary as 0010 000.that's
our
> difference between upper and lower case. So what function can we
use that
> when applied to 74h and 20h results in 54h. I think after a minute
or two of
> noodling that you will come to the conclusion that the XOR function
> perfectly fits the bill here. The XOR function will ensure that we
have a
> true output if we have only one or the other true. Looking at the
bitwise
> operation below it should be apparent:
>
>
>
> 0111 0100 = 74h="t"
>
> 0010 0000 = 20h= the difference between the two characters.
>
> 0101 0100 = 54h after applying the XOR function to our original
character
> code and the 'difference' mask we come up with "T"
>
>
>
> Hope that helps explain it to you and gives you a glimpse into some
of the
> historical aspects of how we got to here from there!
>
>
>
> /tr
>
>
>
>
>
>
>
>
>
> _____
>
> From: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com
[mailto: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com]
On
> Behalf Of Dwight Norris
> Sent: Saturday, February 23, 2008 11:17 PM
> To: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com
> Subject: Re: [helpwithvb] Logical OR as mask for changing case
>
>
>
> Hey Tim could we novice types have a little explanation
>
> it looks fool proof but so does my hand held calculator and it
gives me
> wrong answers all the time
>
> dwight
>
> ----- Original Message -----
>
> From: Tim Rupp <mailto:tim.rupp
...>
>
> To: helpwithvb
yahoogro <mailto: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com>
ups.com
>
> Sent: Saturday, February 23, 2008 7:57 PM
>
> Subject: RE: [helpwithvb] Logical OR as mask for changing case
>
>
>
> To change lower case to upper case XOR the ascii value of the
character with
> 20h.
>
>
>
> "a" = 61h = 0110 0001
>
> Xor 20h = 0010 0000
>
> "A" = 41h = 0100 0001
>
>
>
> /tr
>
>
>
>
>
>
>
>
>
>
> _____
>
>
> From: <mailto: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com>
helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com
> [mailto: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com]
On Behalf Of John Smithman
> Sent: Saturday, February 23, 2008 4:38 PM
> To: helpwithvb
yahoogro <mailto: helpwithvb%40yahoogroups.com">helpwithvb
yahoogroups.com>
ups.com
> Subject: [helpwithvb] Logical OR as mask for changing case
>
>
>
> Many years ago when I was doing a lot of coding, I used a logical
OR to
> ensure that a character was the right case. I am trying to remember
the
> technique.
>
> Has anyone used this foolproof coding trick for changing case?
>
> John
>
.