473,231 Members | 1,644 Online

# xor question

I have a stream of chars where I am trying to xor certain parts. I guess the
meat of my question is that if I xor the hex values:
476f ^ 7262
I get a different value that if I xor the integer values:
71111 ^ 114098
Does anyone know why? I'm assuming that I can't just use the hex values for
xor in c# or am I wrong? It would make my life much easier if I could.

Thanks,
Susan
Dec 14 '05 #1
3 2000
Susan,

Well, considering that 476F does not equal 71111, but rather 18287, and
7262 in hex equals 29282 (and not 114098), I would say that could be one of
the reasons.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Susan" <Su***@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
I have a stream of chars where I am trying to xor certain parts. I guess
the
meat of my question is that if I xor the hex values:
476f ^ 7262
I get a different value that if I xor the integer values:
71111 ^ 114098
Does anyone know why? I'm assuming that I can't just use the hex values
for
xor in c# or am I wrong? It would make my life much easier if I could.

Thanks,
Susan

Dec 14 '05 #2
The "f" suffix on "476f" specifies a float type - you need to prefix hex
values with "0x" - note that hex values default to an unsigned int or
unsigned long if not assigned to a variable.
"Susan" wrote:
I have a stream of chars where I am trying to xor certain parts. I guess the
meat of my question is that if I xor the hex values:
476f ^ 7262
I get a different value that if I xor the integer values:
71111 ^ 114098
Does anyone know why? I'm assuming that I can't just use the hex values for
xor in c# or am I wrong? It would make my life much easier if I could.

Thanks,
Susan

Dec 14 '05 #3
Susan <Su***@discussions.microsoft.com> wrote:
I have a stream of chars where I am trying to xor certain parts.
Do you mean a stream of bytes? If you genuinely mean a stream of chars,
you shouldn't be xoring things at all - it's a really bad idea to treat
character data as binary data.
I guess the meat of my question is that if I xor the hex values:
476f ^ 7262
I get a different value that if I xor the integer values:
71111 ^ 114098
Does anyone know why? I'm assuming that I can't just use the hex values for
xor in c# or am I wrong? It would make my life much easier if I could.

You don't get a different value - you get a compile time error. You
can't XOR an int with a float.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet