A -> 01000001 a -> 01100001
B -> 01000010 b -> 01100010
C -> 01000011 c -> 01100011
. .
Z -> 01011010 z -> 01111010
Observations : fifth bit from the right is set from lowercase serial .
Mask = 1<<5 = 00100000
Ch = Ch | Mask : uppercase -> lowercase
Ch = Ch &( ~Mask ) : lowercase -> uppercase
Code :
int t,n,i;
cin>>t; while(t--) { char
ch;
cin>>ch; int
mask = 1<<5; ch =
ch | mask; //uppercase - lowercase
cout<<ch<<' '; mask =
~(mask); ch = ch & mask;
cout<<ch<<endl; } |
Comments
Post a Comment