xor question

G

Guest

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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.
 
J

Jon Skeet [C# MVP]

Susan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top