This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes bitwise manipulators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "bitwise manipulators" Watch "bitwise manipulators" New topic
Author

bitwise manipulators

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
I am working on a program that requires the use of bitwise manipulators. The problem is that while I can find a lot of articles explaining it lengthy paragraphs, I have yet to find one containing syntax on using it.

The setup I need to create is:



I am just not sure how to properly use manipulators. If you could show me syntax that would be fantastic or better yet show me to an article that contains actual syntax.

I appreciate the help
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14915
    
  26

The operators work just like any other operators such as +, -, * and /.



Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43356
    
  32
Long time since I wrote about bitwise operators. Try here.
Rajeev Trikha
Ranch Hand

Joined: Jan 29, 2010
Posts: 85
Play with this code to clarify your views.

byte number = 0;
if (number > 0) {
System.out.println("Pre: " + number);
number >>= 1;
System.out.println("Post: " + number);

} else if (number == 0) {
System.out.println("Pre: " + number);
number = (byte) ~number;
System.out.println("Post: " + number);
} else if (number < 0) {
System.out.println("Pre: " + number);
number <<= 1;
System.out.println("Post: " + number);
}

Rajeev Trikha (SCJP 6)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: bitwise manipulators
 
It's not a secret anymore!