Results 1 to 3 of 3
  1. #1
    alacn's Avatar
    alacn is offline Senior Member
    Join Date
    Jun 2010
    Location
    UK. near London
    Posts
    118
    Rep Power
    0

    Default static final int DONE = (1 << 9) - 1; ???

    i was just looking over someone elses code and i came across the line of code
    static final int DONE = (1 << 9) - 1;

    could someone please example to me what the (1 << 9) -1 part it doing? ive not seen the << symbol used in any code before.
    Teaching myself java so that i can eventually join the industry! Started in June 2010

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You will want to look up bit shifting to see what this does. Also, when I run across something I don't fully understand, I run little test programs to see what it does, i.e.,
    Java Code:
    public class Fu1 {
       public static void main(String[] args) {
          for (int i = 0; i < 12; i++) {
             int shiftedBit = (1 << i);
             System.out.printf("Shifted by %2d: %d%n",  i, shiftedBit);
          }
       }
    }

  3. #3
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    << just move bits to left.
    It is also useful pair as >> too :)

    byte boo=3<<1;

    the code should move one bit to left I guess...


    read this to know more Bitwise operation - Wikipedia, the free encyclopedia

Similar Threads

  1. Newbie help on visibility and static final
    By tornado in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 01:32 AM
  2. static final field
    By techie.it19 in forum New To Java
    Replies: 3
    Last Post: 10-16-2008, 04:12 AM
  3. Final,abstract and static
    By $hr!k@nt in forum Advanced Java
    Replies: 5
    Last Post: 01-09-2008, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •