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 06-18-2004, 12:19 AM   PM User | #1
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
not understanding BITWISE - how to compare bitwise?

I am doing matching on 'matching bitwise' ---> but its not working...

how do you compare and match and return a true?????

I'm confused
BrightNail is offline   Reply With Quote
Old 06-18-2004, 01:07 AM   PM User | #2
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
did you not have a lengthy discussion with liorean over this?

http://www.codingforums.com/showthread.php?t=39444
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 06-18-2004, 01:17 AM   PM User | #3
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
yes, but it was very confusing - though thoroughly explained....
BrightNail is offline   Reply With Quote
Old 06-18-2004, 02:46 AM   PM User | #4
neofibril
Regular Coder

 
Join Date: Jun 2004
Location: underground
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
neofibril is an unknown quantity at this point
What are the values to be compared?
neofibril is offline   Reply With Quote
Old 06-18-2004, 03:04 AM   PM User | #5
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
the items are already in numeric...

Just comparing numbers.....there is no specific values, as they will change depending on what a person selects.....but, for example.....

7 to 1
or
1 to 0
or
2,1,1 to 4,1,0

or

16 to 3
or
16 to 14

I need to know if they match or are true....if that is possible.
BrightNail is offline   Reply With Quote
Old 06-18-2004, 03:14 AM   PM User | #6
neofibril
Regular Coder

 
Join Date: Jun 2004
Location: underground
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
neofibril is an unknown quantity at this point
Maybe I'm missing something, but wouldn't (value == value) either return true or false?
I think the bitwise comparison is automatic.
neofibril is offline   Reply With Quote
Old 06-18-2004, 11:59 AM   PM User | #7
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
neofibril is right. See the code below to better understand this
PHP Code:
<script>
x=7;
y=1;
b=new Boolean(x==y)
alert (b)
</script> 
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 06-18-2004, 12:18 PM   PM User | #8
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
You are once again making the mistake of asking a general question regarding a specific problem and failing to provide any code so that someone can see what is going on.

You state both "the items are already in numeric" and "there is no specific values, as they will change depending on what a person selects".....

How sure are you that the values are indeed numerics and not strings?
Where are the values coming from?
Can we see some code please?
Willy Duitt is offline   Reply With Quote
Old 06-18-2004, 12:45 PM   PM User | #9
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
anyway, the solution is the same. To return a boolean value of a bitwise comparasion use Boolean() method. Of course, you have to be sure that both values are the same type, or both are numbers or both are strings.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 06-18-2004, 03:16 PM   PM User | #10
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
as long as you arent getting one number from a pulldown, and one from a textbox, the above solution should work. even if you are getting one from each, you could either use the Boolean() method on one or the toString() method on the other (although that may only be in Java, not JS)
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 06-18-2004, 07:40 PM   PM User | #11
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
okay,
let me give this a go...I wasn't familiar with the "boolean" method...

thanks everyone.
BrightNail is offline   Reply With Quote
Old 06-18-2004, 07:44 PM   PM User | #12
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
let us know how it turns out
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson is offline   Reply With Quote
Old 06-22-2004, 11:23 AM   PM User | #13
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
In fact there is no need of a special method as bitwise is an implicit operation

<script>
x=7;
y=1;
alert (x==y)
</script>

will return false

Interesting is that bitwise comparation laways bypasses the string/number differeneces. Thus

<script>
x=1;
y=1;
alert (x==y)
</script>

and

<script>
x='1';
y=1;
alert (x==y)
</script>

will give the same boolean result : true

Thus, canadianjameson, you are wrong, as you don't need to know if the value input is a string or a number.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 06-22-2004, 07:59 PM   PM User | #14
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
fun
__________________
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)
canadianjameson 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:32 AM.


Advertisement
Log in to turn off these ads.