views:

48

answers:

1
char c1 = 'A';
char c2 = 'F';
char final = (char) c1^c2;

This always return the result i am looking for, but it doesn't work if either c1 or c2 contain special characters. Any idea what i can change to allow special characters? Thanks

+1  A: 

"Special Characters" could mean any number of things. If you're trying to represent Unicode code points (which are 32-bit) in chars (which are 8-bit) you're going to encounter problems. Consider using unichar instead.

You may also want to consider using NSStrings instead of managing individual characters yourself, since they take character set into account.

robinjam
thanks, i can't use nsstring, i need to read characters 1 by 1 and encrypt them
aryaxt
Then either treat the char stream as raw data and encrypt it as such, or read up on character encoding. The fact is that some characters just don't fit into chars because the data that represents them is too big. For example the character 私.
robinjam
I got it to work, thanks, chard don't support special characters, but unichars do. I also had to encode the string using NSUTF8Encoder instead of NSASCIIEncoder
aryaxt