homepage Welcome to WebmasterWorld Guest from 54.242.126.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
binary what where?
lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4665982 posted 12:32 am on Apr 26, 2014 (gmt 0)

Quick question for someone who speaks javascript:

This expression
((gRoofLocked & 2^number) != 0)
evaluates to "true" for the appropriate values of the variables involved (currently 31 and some number in the range 1-4).
This expression
(gRoofLocked & (2^number) != 0)
does not.

Question: What, then, does it evaluate to? Is there some weird sequence of operators that I can't figure out?

The fate of the universe does not depend on my learning the answer. But it niggles at me anyway.

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4665982 posted 1:24 am on Apr 26, 2014 (gmt 0)

The != operator has a higher precedence than the & operator, so your second expression can be written like this:
(gRoofLocked & ((2 ^ number) != 0))

I haven't plugged in any numbers, but I imagine that would give you different results than your first example, which would evaluate like this:
(((gRoofLocked & 2) ^ number) != 0)

[developer.mozilla.org...]

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4665982 posted 1:38 am on Apr 26, 2014 (gmt 0)

Note, one of these will evaluate to a boolean while the other will evaluate to a number.

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4665982 posted 7:32 am on Apr 26, 2014 (gmt 0)

Follow-up:

Timestamp says it took me pretty exactly seven hours to figure out that I don't mean 2^blahblah. I mean Math.pow(2,blahblah).

###

Working properly now.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved