Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lower case to upper case

How to convert lower case ASCII char into upper case using a bitmask (no -32 allowed)?

I'm not asking for solving my homework, only some hints.

Thanks

like image 426
Flavius Avatar asked Nov 30 '22 05:11

Flavius


2 Answers

As you state "(no -32 allowed)", I guess you know that the difference between lower case characters and upper case characters is 32. Now convert 32 to its binary representation, there's only one bit set. After that, work out a way to use a bit mask to switch the bit.

like image 175
schnaader Avatar answered Dec 04 '22 23:12

schnaader


Think about the differential between lower and upper case (0x20) and then apply the appropriate mask to your value

XOR to get lower from upper or upper from lower

like image 32
KevinDTimm Avatar answered Dec 04 '22 23:12

KevinDTimm