Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
swapping variables
#14
Orit Wrote:In a digital computer, everything is "number-variables" - that is, binary integers.

Your compiler might balk at xor-ing strings, floating point numbers, or records ("class" "struct" w/e). It might also attempt to do automatic type-conversion to integer, thus ruining your data. But if you can manage to circumvent the compiler's "strong typing", the machine will happily swap any type of data using the xor method.

Yeah, everything in computer programming is binary, we all know that.

But it's rather tedious to x0r strings. You first got to split the strings into char arrays with the longest string as the array-length, then perform xor on each array, and then compile the char arrays into strings again.

Now, doing that instead of
Code:
a = "foo"
b = "moo"
temp = a
a = b
b = temp
?

No thanks, I'm completely fine with this technique.

I get your thinking though, it's possible. Just not efficient for programmer (time-consuming to make the code) nor efficient enough to make an extreme difference unless you swap values every millisecond. (Hell, I'm not even sure if it more efficient at all)
Reply


Messages In This Thread
swapping variables - by GummyBear - 2008-10-24, 02:58 AM
swapping variables - by loddlaen - 2008-10-24, 03:02 AM
swapping variables - by Fiel - 2008-10-24, 03:05 AM
swapping variables - by Stereo - 2008-10-24, 09:32 AM
swapping variables - by GummyBear - 2008-10-27, 12:29 AM
swapping variables - by Horusmaster - 2008-10-27, 12:39 AM
swapping variables - by Russt - 2008-10-27, 01:36 AM
swapping variables - by Horusmaster - 2008-10-27, 02:00 AM
swapping variables - by Russt - 2008-10-27, 02:02 AM
swapping variables - by Horusmaster - 2008-10-27, 02:07 AM
swapping variables - by Nikkey - 2008-10-27, 02:15 AM
swapping variables - by Russt - 2008-10-27, 02:21 AM
swapping variables - by Orit - 2008-10-27, 02:54 AM
swapping variables - by Nikkey - 2008-10-27, 04:51 AM
swapping variables - by Stereo - 2008-10-27, 07:53 AM
swapping variables - by Orit - 2008-10-27, 09:21 AM
swapping variables - by Nikkey - 2008-10-27, 10:17 AM
swapping variables - by Orit - 2008-10-27, 10:49 AM
swapping variables - by Nikkey - 2008-10-27, 11:59 AM
swapping variables - by Devil - 2008-10-27, 12:03 PM
swapping variables - by Orit - 2008-10-27, 12:18 PM
swapping variables - by Nikkey - 2008-10-27, 12:18 PM
swapping variables - by GummyBear - 2008-10-27, 07:33 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)