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 / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Bitwise Operation

Thread view: 
Pasquale Imbemba - 06 May 2004 12:38 GMT
Couldn't see the message Thomas f'ded, so I send this one again:

Hello,

in my little programm:

public class Shift1 {
    public static void main (String [] args) {

    int thirteen = 13;
    int twentysix;

    twentysix = thirteen << 1;

    System.out.println ( thirteen + " is now " + twentysix);
    }
}

I expect 13 (1101) to be shifted by one position to the left, i.e.
becoming 11010. I expected Java to fill the righthand of the bit
sequence with a 0. Since Java uses 32 bit, the result should be just
shifted one left and a zero added, resulting in decimal 26 (thanks
Thomas). But if you compile the above, you get 6.

What is wrong?

Bye
Pasquale
Signature

=======
"I'd like to buy Windows." "Are you mad?" "Why, is this part of the
license agreement"?
=======

VisionSet - 06 May 2004 12:45 GMT
> Couldn't see the message Thomas f'ded, so I send this one again:
>
[quoted text clipped - 19 lines]
> shifted one left and a zero added, resulting in decimal 26 (thanks
> Thomas). But if you compile the above, you get 6.

Well I get 26.

--
Mike W
> What is wrong?
>
> Bye
> Pasquale
Ryan Stewart - 06 May 2004 12:46 GMT
> Couldn't see the message Thomas f'ded, so I send this one again:
>
[quoted text clipped - 29 lines]
> license agreement"?
> =======

I get 26, as expected.
Pasquale Imbemba - 06 May 2004 13:32 GMT
> What is wrong?

If you start mixing up with files and names, that's the error.= 8-0

Thanks to both VisionSet and Ryan Stewart!

Pasquale


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.