Normal Topic @BXor() (Read 1635 times)
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
@BXor()
Feb 17th, 2008 at 10:35pm
Print Post Print Post  
I don't know if I'm using the @BXor() function the wrong way or not, but I'm getting different results with it compared to when I run the same information through the built-in Windows calculator or do the binary math manually on paper.

This code produces an answer of 1015765120, but the calculator and my manual calculations both produce 1234567890163840
Code
Select All
var a as double
var b as double
var c as double

a = 123456
b = 1234567890123456

c = @BXor(a, b)

WriteLn(c) 




Code
Select All
   Decimal                              Binary
          123456 =                                   11110001001000000
1234567890123456 = 100011000101101010100111100100010101011101011000000
======================================================================
1234567890163840 = 100011000101101010100111100100010110101100010000000 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @BXor()
Reply #1 - Feb 17th, 2008 at 10:46pm
Print Post Print Post  
An Exclusive Or function is rarely used on doubles. Try it on integers.

Doubles are stored as 8 bytes with an exponent, mantissa, and sign, as opposed to the straight boolean encoding used for integers across 4 bytes. In the example you have above, it is clear that on the calculator you are using integers (by the number of bits used in the examples of the binary), but the SBasic is using doubles.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: @BXor()
Reply #2 - Feb 17th, 2008 at 11:12pm
Print Post Print Post  
Quote:
Try it on integers.

Same exact results with this:
Code
Select All
var a as int
var b as int
var c as int

a = 123456
b = 1234567890123456

c = @BXor(a, b)

WriteLn(c) 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @BXor()
Reply #3 - Feb 17th, 2008 at 11:22pm
Print Post Print Post  
Quote:
Code
Select All
b = 1234567890123456
 



The value 1234567890123456 overflows a 32 bit integer. A 32 bit signed integer ranges from approximately -2,000,000,000 to 2,000,000,000. An unsigned integer ranges from 0 to 4,000,000,000 - ish.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: @BXor()
Reply #4 - Feb 17th, 2008 at 11:47pm
Print Post Print Post  
Yeah, I just found out that smaller numbers are working. Smiley

Unfortunately, I really wanted to run this on VERY large integers. Not a big deal - I can work around it.

Thanks Mark.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: @BXor()
Reply #5 - Feb 17th, 2008 at 11:51pm
Print Post Print Post  
BTW...
Just remembered, the reason I was using Doubles was because I knew Integers have a size limit, but then forgot about it when you suggested to use them. Roll Eyes
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @BXor()
Reply #6 - Feb 17th, 2008 at 11:59pm
Print Post Print Post  
If I may ask, what are you up to?

You may be able to manage to work with large entities by bit shifting each byte in the entity into one byte in an array of single bytes, and then xor-ing those bytes. This is a very simple and effective means of encryption (but you didn't hear that from me!)
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: @BXor()
Reply #7 - Feb 18th, 2008 at 12:26am
Print Post Print Post  
Yeah, I was looking at encrypting some data. But, it may be easier to use TrueCrypt on the file itself.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @BXor()
Reply #8 - Feb 18th, 2008 at 12:28am
Print Post Print Post  
If its an ASCII file, read it in and operate on it byte by byte (as a string).
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged