471,305 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

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 1957
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
KH
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
If replying to the group, please do not mail me too
Dec 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mohammed Mazid | last post: by
3 posts views Thread by Stevey | last post: by
10 posts views Thread by glenn | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.