Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

bitwise manipulators  RSS feed

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 15860
80
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The operators work just like any other operators such as +, -, * and /.

 
Campbell Ritchie
Sheriff
Posts: 53750
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long time since I wrote about bitwise operators. Try here.
 
Rajeev Trikha
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!