|
Thread: Xor
-
Apr 2nd, 2003, 09:09 AM
#1
Thread Starter
Member
Xor
I know this has been covered before I have searched the archives
But I still don't understand this!!
Why does v = 9 Xor 10 = 3???
Can someone please explain this very slowly for me
I am having a bad day with this
Thanks in advance
-
Apr 2nd, 2003, 09:15 AM
#2
-
Apr 2nd, 2003, 09:18 AM
#3
Thread Starter
Member
Great thanx alot that has cleared thingsup
I never thought I was going to get this one
One thing though is there a conversion function in vb where I can convert numbers to binary to have a look at what is going on myself?
Thanks again
-
Apr 2nd, 2003, 09:26 AM
#4
Frenzied Member
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0
Since the high-order bit is 1 in both values, they = 0 in the result. This leaves bit 1 (= 1 in 9 and = 0 in 10) and bit 2 (= 0 in 9 and = 1 in 10) which will both = 1 in the result.
10 - 1010
09 - 1001
---------
03 - 0011
-
Apr 2nd, 2003, 09:27 AM
#5
-
Apr 2nd, 2003, 09:30 AM
#6
Thread Starter
Member
I am slowly getting to grips with it
But still the binary to integers is confusing
Could you try again??
Thanks alot
-
Apr 2nd, 2003, 09:53 AM
#7
Fanatic Member
A (hopefully) simple explanation:
Suppose, you have the number 2345, which is a normal, decimal integer.
2345 =
5 + 40 + 300 + 2000 =
5 * 1 + 4 * 10 + 3 * 100 + 2 * 1000 =
5 * 10^0 + 4 * 10^1 + 3 * 10^2 + 2 * 10^3
The value of each digit is influenced by the position. The more to the left, the higher the value. The rightmost digit has to be multiplied with 10 ^ 0 (= 1). For each digit to the left the exponent of the power is increased by one: 1 -> 10 -> 100 -> 1000, etc.
For binary values (or octal or hexadecimal) it is the same. Only, the base (called "radix") isn't 10, but 2 (or 8, or 16).
So, to convert the binary value 100101 to a decimal value, you have to add 1 * 2^0 + 0 * 2^1 + 1 * 2^2 + 0 * 2^3 + 0 * 2^4 + 1 * 2^5. For sake of ease, you can simply skip the zero-values. This will result in 1 * 1 + 1 * 4 + 1 * 32, which sums up as 37.
-
Apr 2nd, 2003, 09:55 AM
#8
Fanatic Member
Oh, and coming back to the Xor-operator:
9 Xor 10 = 3, 10 Xor 9 = 3.
But: 9 Xor 3 = 10, 3 Xor 9 = 10.
And 10 Xor 3 = 9, 3 Xor 10 = 9.
Because Xor is reversible, it is used in many (simple) encryption algorithms.
There is no normal numerical relation between the values you give in and the result, it is purely binary as manavo11 explained.
-
Apr 2nd, 2003, 09:59 AM
#9
Thread Starter
Member
Thanks alot for all of yyour replies
I have managed to get my head around with this
37 would be
0 0 1 0 0 1 0 1
128 ,64, 32, 16 ,8 ,4, 2, 1
adding 32+4+1
-
Apr 2nd, 2003, 10:09 AM
#10
Frenzied Member
VB Code:
Public Function ToBinary(ByVal lIn As Long) As String
Dim sBinary As String
Dim nIndex As Long
Dim lMask As Long
For nIndex = 0 To 30
lMask = 2# ^ nIndex
If (lIn And lMask) Then
sBinary = "1" & sBinary
Else
sBinary = "0" & sBinary
End If
Next nIndex
If lIn < 0 Then
sBinary = "1" & sBinary
Else
sBinary = "0" & sBinary
End If
ToBinary = sBinary
End Function
-
Apr 2nd, 2003, 10:14 AM
#11
Thread Starter
Member
Anyone want to have a go at getting from a int to a hex??
-
Apr 2nd, 2003, 10:17 AM
#12
Retired VBF Adm1nistrator
Hex()
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 2nd, 2003, 10:35 AM
#13
Thread Starter
Member
Originally posted by plenderj
Hex()
Thats wasted on me
-
Apr 2nd, 2003, 10:43 AM
#14
Frenzied Member
-
Apr 2nd, 2003, 10:45 AM
#15
Thread Starter
Member
I have seen the light
Thank you all
You have been most helpful
-
Apr 2nd, 2003, 10:52 AM
#16
Frenzied Member
And to get from Hex back to int:For example:
VB Code:
Hex(10) = A
CInt(&HA&) = 10
Hex(510) = 1FE
CInt(&H1FE&) = 510
-
Apr 2nd, 2003, 01:46 PM
#17
-
Apr 2nd, 2003, 02:04 PM
#18
And just for your entertainment, remember that the calculator bundled with all versions of Windows has the means to convert decimal to hex to binary, etc, and you can do some logical calculations with it. I find it very handy when flipping bits in bitmasks.
-
Apr 2nd, 2003, 03:01 PM
#19
Thread Starter
Member
Yes I have been using the calculator to confirm things as I have been going along.
I would like to thank everyone again you have all been very helpful on a topic I thought I would never really get to grips with, but feel quite comfortable with now.
Thanks again
-
Apr 2nd, 2003, 03:16 PM
#20
Lively Member
I wrote a bitmask calculator in php, which is here.
I find it quite handy at times when I want to know what specific bits are set, rather than just what the equivalent binary/decimal number is.
-
Apr 3rd, 2003, 02:37 AM
#21
Thread Starter
Member
Ok then chaps sorry to keep banging on about this, but its getting quite interesting now
With my newly found understanding of Xor what can I do with it
A little bit of encryption perhaps?
Does anyone fancy showing me how?
ps.Whats this triple des thing all about?
Thanks again
Last edited by DirkDiggler; Apr 3rd, 2003 at 02:51 AM.
-
Apr 3rd, 2003, 03:03 AM
#22
Retired VBF Adm1nistrator
Xor provides very weak encryption.
And triple DES is the DES algorithm run three times over your data.
Its a 56bit encryption algorithm if I remember correctly.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 3rd, 2003, 03:04 AM
#23
Thread Starter
Member
Don't suppose you have any examples of the two
-
Apr 3rd, 2003, 06:30 AM
#24
-
May 28th, 2003, 02:06 PM
#25
Lively Member
I know I'm resurrecting an old thread here, and I don't normally like to do that, but I wanted to mention that it's not just simple weak encryption methods that use Xor.
As an example, Blowfish, a very well known and respected encryption algorithm, uses Xor.
Also, Xor is the basis for the one time pad, which, while difficult to implement correctly, is very simple and has been called unbreakable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|