permaculture playing cards*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 14074
    
  16

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



Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bitwise manipulators
 
Similar Threads
Java-4a Please
problem with mask and bitwise manipulator
shift operator
Binary in java - guide me
my notes on JLS for any1 who needs them !!