Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2004, 07:39 PM   PM User | #1
Tails
Regular Coder

 
Join Date: Nov 2002
Posts: 672
Thanks: 1
Thanked 1 Time in 1 Post
Tails is an unknown quantity at this point
Bitwise manipulation with negatives

I've been working on reading a certain encoding from a game's password system. I've successfully been able to make a script to output code, but now I'm making a script to read it as well.

Here's the interesting part. Not only does it use different bits in a 0 to 15 hex variable, but some bits are negative.

+1 = Event 1
-2 = Event 2
+4 = Event 3
±8 = Event 4

The variable is 13 (D) by default, so I tried this:

X-=13 // now we can get the offsets of it's modification
if(X&-4){alert('event 1')}
if(X&2){alert('event 2')} // works
if(X&-1){alert('event 3')}

Let's say X was -4, then for some reason all 3 would fire as true. Is there a legal use of using negative integers with bitwise manipulation? Or should I multiply by -1 if a variable is less than 0?
Tails is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:45 AM.


Advertisement
Log in to turn off these ads.