Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 What does this do?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SJ




PostPosted: Sun Apr 13, 2008 3:44 pm   Post subject: What does this do?

What does ">>" and "<<" mean or do in Java? I've seen it in contest solutions on topcoder several times, but I have no idea what they do..

so like,

for (int i = 0; i < 1 << 3; i++)
System.out.println (i);

prints numbers from 1 to 7

for (int i = 0; i < 1 << 13; i++)
System.out.println (i);

prints from 1 to 8191

i mean, they even got arrays difined like int [] a = new int [1<<3]; and if statements like if (x < (2<<5))

what does this symbol mean?

and what do you call it?
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Sun Apr 13, 2008 4:02 pm   Post subject: RE:What does this do?

<< is the left shift operator and >> is the right shift operator.

For more info see: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op3.html

It bascly shifts all the bits in the numer left or right by a given amount. <<< and >>> are unsinged versions of the same command.


You probly don't want to use thess comands on decmal numbers unless you know what you are doing, understand binnary and how numbers are repserented in bits.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
SJ




PostPosted: Sun Apr 13, 2008 6:29 pm   Post subject: RE:What does this do?

Wow I never knew these existed. Thanks dan, that link felt like a holy grail if anything Smile
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: