java - How to convert cases with bit manipulation? -
how can convert uppercase lowercase , vice versa using bit manipulation?
in ascii, uppercase characters prefixed 010 , 1-26 in binary [their location in alphabet]. lowercase prefixed 011.
by using bitwise or operand , 00100000 mask 0b00100000, 32 integer, can convert uppercase lowercase, , not change lowercase.
example
char character = 0b00100000 | 'a'; or
char character = 32 | 'a'; to convert uppercase, use
char character = 0b01011111 & 'a'; or
char character = 95 & 'a'; you may use way of representing 127 or 95 bitmask , operation.
Comments
Post a Comment