The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

I was given a challenge for Perl; by caffine-iv2003-01-19 02:34:14
  Interesting... by Spazmatic2003-01-19 09:40:41
    Stavros' XOR solution doesn't risk overflows by kahuana2003-01-19 09:52:32
      Overflow isn't really a problem. by Beorn 2003-01-19 11:37:40
The addition-subtraction method works for all integers, because the numbers wrap around.

Example with single-byte valiables treated as natural numbers:

a = 250;
b = 10;

a = a + b;   a is now (250 + 10) mod 256 = 4.
b = a - b;   b is now (4 - 10) mod 256 = 250.
a = a - b;   a is now (4 - 250) mod 256 = 10.

I'm not sure how it would work with floating point variables. The xor method on the other hand works on any fixed-size type.
[ Reply ]

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)