Skip to main content

Good tutorials on Bitwise operations in Java


Can anyone please point me to good online tutorials on Bitwise Operations (preferably in Java)? Before anyone write LMGTFY, I've already Googled it but couldn't find one with good examples. Java's own tutorial is also not that extensive and doesn't clearly explain what is going under the hood. I'm a visual learner; so, if there are any resources with good 'working' examples, that would help me a lot. Thanks.



Source: Tips4all

Comments

  1. Vipan Singla's page on Bitwise Operations is quite nice.

    It is not language specific, but luckily, these operations work the same on Java as many languages (in particular, nearly all C-style languages work this way with bitwise operations). It is very visual, and uses tables to illustrate what happens by operation.

    ReplyDelete
  2. Additionally to the good introductory guide that Reed Copsey recommended I'd recommend a intresting collection of small real world samples that show what you can actually do with bit operators and that you might enjoy reading and experimenting with once you have got some basic understanding of how bitwise operators work.

    Regarding the differences of bitwise operators between Java and C/C++: In Java you don't have unsigned numeric types (except char) but instead you have two right shift operators (>> and >>>) that allow you to do either a signed (>>) or a unsigned shift (>>>). A signed right shift copies the sign bit to all empty places on the left side while a unsigned right shift fills them with zero bits. Also, as booleans in Java cannot be be cast to ints, you cannot use boolean expressions directly as operands for bit operators. I.e. something like this works in C but not in Java:


    val |= ( a > b );


    In Java you would have to write this insead to do the same thing:


    val |= ( a > b ) ? 1 : 0;

    ReplyDelete
  3. What's wrong with the WIkipedia article?

    ReplyDelete
  4. A perennial favorite: Sean Eron Anderson's Bit Twiddling Hacks.

    ReplyDelete
  5. As an introduction to bitwise operations to represent sets and efficiently compute subsets I liked this tutorial. It contains links to samples, including Java code (if you keep following the links at the bottom of the linked pages).

    ReplyDelete
  6. Also check Hacker's Delight, there is a sample chapter which is available online. Though not specific to Java, the programming tricks explained here would be applicable with Java also.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex