aspose file tools*
The moose likes Beginning Java and the fly likes Binary AND Operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary AND Operator" Watch "Binary AND Operator" New topic
Author

Binary AND Operator

celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Hi Folks,
I made a post a while ago called Manipulating Binary Numbers. Basically what i am trying to do is make an LED. I need to read a Byte of input & where there is a 0 in the binary input, the corresponding 'segment' of the LED is lit.
I received the following in reply to my last post:

Where 'charWord' is declared as:

But, when i try to run this i get the following error from the compiler:
"operator & cannot be applied to byte,boolean"
Does anyone know how i can apply the binary AND operator in Java?
Thanks & Regards,
Celine


We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br />- Robert Wilensky
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Hi Celine,

This may be a precedence problem. The whole if result should be boolean, so use brackets to force the "and" action first.

Not sure about your logic, though. Normally your byte would be progressively tested against a rotating bit set in a mask.
Ed
Fighting the trend for signature blocks . . . . .


The nice thing about Standards is that there are so many to choose from!
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
The '00010000b' is not a valid identifier.


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
Guys,
I changed the brackets & it works perfectly. Also, i set up variables for the bytes i needed to compare my word to - 0000001b etc. were not valid but 'byte one = 1;' is very valid!
The guy that replied to the last post was totally on the right track. This is perfect for what i need. You are all lifesavers! Thank you so much!
Best Regards,
Celine
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Binary AND Operator