XOR output

I've bee looking all day for good information on this question and have come up nearly empty.
if I have this:
result = 'a' ^ 'd';

What type should result be?
What is the value of result?

Thanks
If a and b are char type - the result will be int.
Well, the two values are of type char, so the result should also be a char.
However, with this type of manipulation, the result is not guaranteed to be a displayable character, so you may want to treat the values as integers instead.
I 'll go and double check my answer - I would have sworn..
Well, I'm using xor on string which I'm breaking into characters and I see the value of breaking it down to integers from there. Casting it into an integer array seems to work fine though, although really it's hard to tell.

I think it really comes down to how the number is to be displayed. Internally we have just the binary representations:

'a' = 01100001
'd' = 01100100


'a' ^ 'd' = 00000101


Since all of these bit patterns will fit into a char type, then that is adequate. An int is a perfectly acceptable alternative, it just puts some leading zeros on the beginning.
Last edited on
Topic archived. No new replies allowed.