Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

a quizz question about java bit operation???

Thread view: 
tyshanchn - 10 May 2006 04:03 GMT
hi ,

what is the value of

-8>>-1
-8<<-1

it will be like

public class BitOperation {

    /**
    * @param args
    */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(-8 << -1);
        System.out.println(-8 >> -1);
    }

}

the result is
0
-1

but if not -8, what will be the value?and why???
Thomas Schodt - 10 May 2006 10:10 GMT
> hi ,
>
[quoted text clipped - 21 lines]
> 0
> -1

int bitshift only uses the last 5 bits of the right hand side argument
(long bitshift uses the last 6 bits).

 -1 & 0x1f is 31

the rest is obvious.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.