• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bitwise manipulators

 
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
Saloon Keeper
Posts: 15448
41
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
Pie
Posts: 49823
69
  • 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);
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic