char to binary conversion
hello, I have a question about how to convert a single character to its binary equivalent. I have find the way to do it for integer numbers:
Code:
int c=8;
while(c>0) {cout<<c%2;c=c/2;}
to show the 'reversed' binary. also I have find the way to do it with plain characters, only get its ascii and do the same as before, so:
Code:
int bin[8];
int pe;
char c='a';
printf("dec:%d\n",c);
pe=7;
while(c>0)
{
bin[pe]=c%2;
c=c/2;
pe--;
}
for(int np=pe;np>=0;np--) {bin[np]=0;}
printf("bin:");
for(int q=0;q<8;q++) {printf("%d",bin[q]);}
printf("\n");
but how can I convert an accentuated character to its binary representation? the method of convert its ascii number does not work here. also seems not to work here the loop though a
while(c<0)
mutiplying instead '%'.
How can I do it?
Thank's in advance
Niara