Bitwise Operator ( ) help

I'm a new beginner and I have some problems with such code:
class Test {
     public static void main(String[] args) {
          int i = -1;
          int a = i;
          for ( int k = 0 ; k < 32 ; k ++ ) {
               i = i >>> 1;
               System.out.print(i+" ");
               System.out.println(a >>> (k+1) );
I hope that the two columns of the output wil be the same, but the
last line isn't.
Why a == -1 after " int a = -1; a = a >>> 32 " ? I think a should be 0.
Am I right or is there any mistake?

See the language spec:
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5121
in particular:
If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (�15.22.1) with the mask value 0x1f. The shift distance actually used is therefore always in the range 0 to 31, inclusive.
Though it doesn't say why.

Similar Messages

  • Bitwise operator question...

    Hi,all.
    I have been using Java for around 1 year, but still not very comfortable with bitwise problems. I wish some one can give me a thorough explanation for these. Better yet, if you know how to use bitwise operator to solove the real programming problem, please post here too. I am doing some testing now. I will post some coding example later here, so you may help me on these coding too.
    Everyone have a great sunday night.

    Integers are represented by 32-bit values. You can have either 'signed' or 'unsigned' integer ranges.
    signed int 32000 to - 32000
    unsigned int 0 to 65000
    (note, these are approximations)
    For signed interpretations, the last digit on the left hand side represents wether or not the value is negative (called the most significant bit, msb).
    1000 0000
    The '1' is the msb
    Steps to convert -14 to its binary representation (using 2s complement as explained by above post):
    1. write the binary representation of '1' (ignore negative for now)
    2. invert the values
    3. add 1
    1) 0000 1110
    2) 1111 0001
    3) 1111 0010
    As you can see, the msb is a '1', so therefore it represents a negative value
    Note: In binary addition,
    1 + 1 = 0 carry 1
    1 + 0 = 1
    0 + 0 = 0
    As for other applications of this, I find myself using bitwise calculations in graphical work.
    As stated above (I love to reiterate others words, cause it's fun!!), Assembler language programming is a fantastic way to become an expert in the art of bitwise manipulation (if you have the patience).

  • How to make Bitwise operation in Labview ?

    Hello.. everyone,
    I need to make the bitwise operation (or) in Labview, but I can't find it somewhere!!!
    Anybody has the experiece about it, pls help me !!
    Thanks a lot

    Hi Nok,
    The standard OR function in the boolean sub palette of the functions palette performs a bitwise operation on it's input data. This is a polymorphic function so you can input scalar booleans, arrays of booleans or numerics.
    Hope this helps,
    Nick

  • Does bitwise operation on boolean datatypes work like logical operation ?

    Does bitwise operation on boolean datatypes work like logical operation ?
    For example, in the following code, how is each bitwise operation (say) 'b1 & b2' evaluated ?
    1) by converting the values of b1 (true) and b2 (false) to binary and doing '&' on them OR
    2) just treating it as a logical operation (i.e. similar to &&) where both have to be equal to be true
    Also, does the outcome of the if condition need to result in a 'true' or 'false' for the relevant message to print ? ....... Just fyi, I tried out this program and it goes to condition 2 but I do not understand why.
    class SSBool {
    public static void main(String[] args) {
    boolean b1 = true;
    boolean b2 = false;
    boolean b3 = true;
    if (b1 & b2 | b2 & b3 | b2)
    System.out.println ("condition 1");
    if (b1 & b2 | b2 & b3 | b2 | b1)
    System.out.println ("condition 2");
    Thank you,
    AG

    The Java Tutorial (always my first stop if I need an answer) says :
    "When both operands are boolean, the operator & performs the same operation as &&."
    That your program goes to condition 2 is obvious because the last test in the if-clause if (b1 & b2 | b2 & b3 | b2 | b1) looks at b1 which is true...

  • Please help explain these bitwise operations!

    I am working with a file that has a header with the size of the file encoded into 4 bytes like:
    >
    The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 02 01.
    I have found someone's code that puts this together into the integer value, but i don't understand why they do each step. Is there anyone here who can explain this code to me?
    //Read in the bytes (why do they read char[] instead of byte[]?)
    char[] tagSize = br.ReadChars(4);    // I use this to read the bytes in from the file
    //Store the shifted bytes (why is it int[], not byte[]?)
    int[] bytes = new int[4];      // for bit shifting
    int size = 0;    // for the final number
    * Why are they combining these bytes in this way if they're
    * going to again combine them below (in the line setting "size")?
    //how do they know they only care about the rightmost bit on the 3rd byte?
    //how do they know to shift it 7 to the left?
    bytes[3] =  tagSize[3] | ((tagSize[2] & 1) << 7) ;
    //Why do they use 63 here (I know it's 111111)?
    //how do they know they only want the 3 rightmost of byte 2nd byte?
    //And how know to shift it 6 to the left?
    bytes[2] = ((tagSize[2] >> 1) & 63) | ((tagSize[1] & 3) << 6) ;
    bytes[1] = ((tagSize[1] >> 2) & 31) | ((tagSize[0] & 7) << 5) ;
    bytes[0] = ((tagSize[0] >> 3) & 15) ;
    //how do they know to shift these bytes the amount that they do to the left?
    size  = ((UInt64)bytes[3] | ((UInt64)bytes[2] << 8)  | ((UInt64)bytes[1] << 16) | ((UInt64)bytes[0] << 24)) ;

    6tr6tr wrote:
    You've GOT to be kidding! I posted only ONCE on THIS forum. Javaranch is owned by a different company and does NOT have all the same members that this web forum has. Posting the same question on completely different websites' forums is NOT cross-posting. Cross-posting is posting the same thing in different boards of ONE website's forums.Absolute rubbish. Here a couple of links for you:
    Wikipedia:
    [Crossposting is the act of posting the same message to multiple forums, mailing lists, or newsgroups.|http://en.wikipedia.org/wiki/Crossposting]
    JavaRanch's FAQ:
    [There might be times when you are inclined to post a question not only at JavaRanch, but also at some other site. When you do so, keep in mind that this is not generally in the interests of the posters who might be responding to your posts - those folks may find they've wasted their time. You certainly don't want to annoy those you want to help you, so you might want to make the experience as painless as possible.|http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites]
    Sun's FAQ, section C2:
    [Post once and in the right area: Multiple postings are discouraged, because they make the category lists longer and create more email traffic for developers who have placed watches on multiple categories. Because of this, duplicate posts are considered a waste of time and an annoyance to many community members, that is, the people who might help you.|http://wikis.sun.com/display/SunForums/Forums.sun.com+FAQ]

  • Logical bitwise operator

    Hi ALL
    Logical bitwise comparison operator 'O' is used between two operands say A and B as "A O B".
    A is of type INT1 and B is of type X.
    The above mentioned line was working fine till enabling unicode check. But now it says A should be of type X or Xstring.A's type cannot be changed since it is derived from a std structure.
    Is there some other operator which does the same function as operator 'O'?
    Regards,
    Navaneeth

    Hi,
    Check this..
    IF.....XOR.....
    Regards
    Vijay

  • BitWise Operations in java

    hi Guys
    Can any one help me out in explaining the below program
    public class Bitwise{
    public static void main (String[]args){
    int x=12&13;
    int y=x^6;
    System.out.println(y I 3)
    Pls help me with the above program in detail explanation
    Raghu

    Here's a better idea. You start by:
    1) adding print statements to print out x and y immediately after they're set.
    2) predicting what you think each print statement will produce, consulting your favorite text or tutorial (see below links) or the JLS if you need to.
    3) running the program.
    4) seeing if the results match what you expected.
    5) trying to figure why they didn't match, if they didn't.
    6) poting a specific question here about what you expected and why, and what you saw instead, if you're unable to figure it out.
    Installation Notes - JDK 5.0 Microsoft Windows (32-bit)
    Your First Cup of Java
    New to Java Center
    The Java&#8482; Tutorial - A practical guide for programmers
    The Java&#8482; Tutorial - Trail: Learning the Java Language
    Java Programming Notes - Fred Swartz
    How To Think Like A Computer Scientist
    Introduction to Computer Science using Java
    The Java Developers Almanac 1.4
    Object-Oriented Programming Concepts
    Object-oriented language basics
    Don't Fear the OOP
    Books:
    The Java Programming Language - 4th Edition
    Head First Java, by Bert Bates and Kathy Sierra
    Thinking in Java (Free online), by Bruce Eckel
    Core Java, by Cay Horstmann and Gary Cornell
    Effective Java, by Joshua Bloch
    http://java.sun.com/developer/Books/javaprogramming/
    Intermediate
    The Craftsman Series
    Java Design: Building Better Apps and Applets (2nd Edition)
    Head First Design Patterns

  • CS2 AI Error "Could Not Complete The Requested Operation" HELP!!

    So I open AI this morning same as always and I get this error message "Could Not Complete The Requested Operation" Click OK and AI Crashes, reboot, restart - same thing. I did some digging around the web and found a few solutions..none worked, well sorta. If I delete all of the fonts on my machine I can get AI to open normally, as soon as I start putting fonts back in - errors start occuring again!
    HELP!! I have reinstalled, also to no avail.

    The machine (PC WINXP) won't allow you to delete certain fonts.
    I tried your idea, I have 1311 fonts currently installed, it will take hours and hours to test it out. I did some batches and AI continued to open till I got to the "C" fonts, then even 1 at a time I was never able to get AI open again. I would install a font, check AI, remove font, install a different font, check AI, same problem.
    Any other suggestions?
    I will try FAQ 2

  • Time Schema & PCR - Operation Help

    Hello Gurus,
    I have a scenario where in I have to change the processing type / time type class in a PCR. I know that the configuration can be done for this in table T555Y table for this. But my requirement is that I should be doing this in a PCR in the custom schema. I am looking for a operation like colop XXXX , which changes the time type. I need to change the processing type / time type instead.
    FILLP operation does not serve the purpose as it can change the processing type entry in TIP table but not the processing type / time type entry in TIP.
    Any help in this regard is much appreciated.
    Thanks,
    Saroj.

    Hi,
    although SAP - documentation provices the following info:
    The processing type/time type class is determined when the time data i
    imported. For absence and attendance records from infotypes 2001/2002,
    this class is read according to the subtype in the "Absence: Time
    Evaluation" table (T554S), in the "Processing type/time type" field.
    For all other time data, field TIP-CLTIM has an initial value of "00".
    Field TIP-CLTIM can be queried using operation OUTTP and changed using
    operation FILLP.
    I can't figure out which parameter to use. Nor via documentation nor via some searching in the relevant coding for operation FILLP.
    Wilfred.

  • Internal Table Operation Help Required

    Hi
    I have to insert 8 counters p1-p8 in a field BANFN of ITAB1.
    Like this their are 3 more fileds.I have to show the no. for PR released frm JAN-DEC in ALV format.I had doen the calualation,but unable to insert these conters in ITAB1 to do final calculation & display the result.
    Please help me.
    I had used : insert p1 into itab1-banfn where sy-index 1.
    Like this I had tried out many comands,but al in vain.PLZ help me in this regard.
    Regards.
    Vipin

    There are 8 fileds in my internal table,in which 1st one is for MONTH(JAN-DEC).
    The ALV is only suppose to display 12 rows,containing each month per row.
    Now for each month I have to display the PR converted to PO & the avg lead time for each month.So I had calu all the data ,but now I have to insert 12 counters in 4 fields.one for No of PR converted to PO in each month,than one for AVG LEAD TIME for each month.so there has to be 12 + 12 counters for each row.Similar operation I have to perform for the PR pending fo PO.So there has to be 24 more counters for again 2 diff fileds.Now I had calcuated the data,but the problem is this ,,,,,how to insert each ctr in each row.
    EG: insert ctr1 into itab1-banfn where itab1-mmyy = 'January' or sy-index = 1.
          insert ctr2 into itab1-banfn where itab1-mmyy = 'Febuary' or sy-index = 2.
          move crt1 to itab1-banfn where sy-index = 1.
    None of the operation is working.
    Like this i have to insert 48 counters in all rows for these 4 diff fileds.
    Pl help me in thsi regard ,if possible.
    regards.

  • Simple math operation - Help needed

    Hi, i have a simple mathematical operation to do, related to
    a shooping cart, which i want to keep simple.
    I have a input text box named QT1, where customers indicate
    quantity
    I have a dymanic text box, named ST1, where i want the value
    of QT1 to be multiplied by 10$ (hence 10)
    on the release of the button. I have a NaN answer. Here is
    the code.
    on (release) {
    var qt1:Number;
    st1 = qt1 * 10;
    And then, a grand total button will add ST1 + ST2 + ST3, with
    GT the name of the grand total dymamic box:
    on (release) {
    gt = st1 + st2 + st3;
    The second part works, but the first one, with QT1 is giving
    me a Nan (not a number) answer.
    Any help appreciated.

    Problem solved. That cary Auto-kern thing....

  • My site won't load in chrome or opera.help please

    Hi
    Im having problems with my site and have tried everything.
    It loads properly in Safari and Firefox and on android phones,but it wont pass the pre-loader in google chrome or iphone and in opera its totally screwed up ,everything is everywhere.
    hopefully theres some type of code or something out there to fix this problem..i could careless about opera.but chrome  and iphones are used by many these are mandatory .
    my site is Royce G Design    ( www.roycegdesign.com )
    please help someone

    Hi
    Im having problems with my site and have tried everything.
    It loads properly in Safari and Firefox and on android phones,but it wont pass the pre-loader in google chrome or iphone and in opera its totally screwed up ,everything is everywhere.
    hopefully theres some type of code or something out there to fix this problem..i could careless about opera.but chrome  and iphones are used by many these are mandatory .
    my site is Royce G Design    ( www.roycegdesign.com )
    please help someone

  • MSI TV@nywhere: closes with illegal operation Help!!!

     
    hello everyone
    I am using MSI Tv@nywhere on a WinXP SP2/P III 192mb ram machine. Whenever I try to run the software (WinDVR 2.0.34 Branch Release), I get an error "InterVideo?WinDVR Application has encountered a problem and needs to close. We are sorry for the inconvenience." asking me to send an error report to Microsoft (some data error report details are.. AppName: windvr.exe AppVer: 2.0.34.198 ModName: iviscapt.ax ModVer: 2.0.34.198 Offset: 00001fc4) I have tried reinstalling the software many a times but didnt help at all
    please do post your suggestions..
    regards

    https://forum-en.msi.com/index.php?topic=73940.msg521242#msg521242
    Quote
    "MSIPVS installs, but when I start the application I get an error message "WinDVR has caused a problem and needs to shutdown" "
    hpkuo credits this to sizzle in his hints and tips thread, but I'll elaborate a little. The problem is caused by QuickTime codecs installed by Nero 6.3.1.15. It is unclear whether later versions of Nero were fixed, but earlier versions should be okay. "A "quick fix" is to rename the files "NeQTADec.ax" and "NeQTVDec.ax" in "C:\Program Files\Common Files\Ahead\DSFilter\"."

  • File operation help required

    hello gurus,
    I want to check whether a perticular file present on the application server or not
    if yes
    I want to delete it.
    if no
    i want to create the file in append mode.
    I know its a simple issue but still i havnt done file IO in sap yet so please help me in this issue.
    Thanks in advence!!!

    Hi Nikhil,
    It is very simple.
    1. open dataset <dset> for input.
        If the file is existing, you will get sy-subrc = 0, else sy-subrc = 8.
    2. if sy-subrc = 0   DELETE DATASET <dset>
    3. else.
        OPEN DATASET <dset> for APPENDING.
    Ravi

  • How to convert bitwise operator for oracle

    hi all,
    Please help me to get convertion for (IP/16777216)&0xFF like
    If I have query select (IP/16777216)&0xFF I need IP address like 10 is there any way to do this
    Thanks in Advance
    Prashant

    Hi..
    Well not very clear with the question.
    If you want the ip you can use
    select utl_inaddr.get_host_address(Host_Name) from V$INSTANCE;
    If you want some conversion from decimal to hexadecimal you can refer to
    [http://arjudba.blogspot.com/2008/10/convert-decimal-to-hexadecimal-on.html]
    [http://www.jlcomp.demon.co.uk/faq/base_convert.html]
    Anand

Maybe you are looking for

  • Music found, but not being read

    So i was on a plane when my ipod started acting up just skipping songs. So I reset it. Though when I did that it showed all my songs were gone. Though the space for the songs is still there. i then found the files looking on my computer. how can I ge

  • Lg cosmos 2 call quality

    when i place a call to anyone whether land line or any other cell, the call on their end is not clear and i have to call back using a different phone.  this recently happened after i had paired my bluetooth with this phone.  i have removed the item f

  • F4v in IE 7 fails - no metadata?

    Hey all - I'm having trouble with my new player in IE 7 (it works great in all other browsers, of course). It seems that in IE 7, it is waiting until the full file downloads in order to get metadata; what this means is that the player itself is not b

  • Assignment of Logical Structures to Users

    Hi, I have a question regarding the assignment of logical structures to users of a database. The following is what Sam Alapati states in his book "Expert Oracle9i Database Administration:" "By organizing space into logical structures and assigning th

  • Relate to DehydrationStore in Oracle Soa suite 11g

    Can you explain what are the steps required to configure dehydration store ? In DB which contain the dehydration store informtion?