Bitwise Operators - Different Output ?

Hello !
Can anyone please as to why these two different programs are giving different values ? Both are using Right
Shift Operator >>> .
The first shifts right the value a set to -1 to 24 bit positions giving a = 255 . But with the second program
doing the same in a loop we start getting zero from the 9 iteration and continues till 24 ( and onwards ) . Why
are we not getting the same value for a from the two programs ?
// Right Unsigned Shifting : >>> ( Shift Right zero fill )
class RUnsignShift {
public static void main(String args[]) {
int a = - 1 , b = 0 ;
System.out.println("\nDemonstration : Right shift zero fill Operator >>> ");
System.out.print("Original value int a = " + a +" ") ;
System.out.println("Bit pattern : 11111111 11111111 11111111 11111111");
b = a ;
a = a >>> 24 ;
System.out.print("a = -1 >>> 24 (Zero-fill) bit positions a = " + a +" ");
System.out.println("Bit pattern : 00000000 00000000 00000000 11111111");
b = b >> 24 ;
System.out.print("b = -1 >> 24 (Sign Ext.) 24 bit positions b = " + b +"\n");
SECOND PROGRAM
class RUnsignShift2 {
public static void main(String args[]) {
int a = -1 , i ;
System.out.println("Demonstration : Right shift zero fill Operator >>> ");
System.out.print("Original value int a = " + a +" ") ;
System.out.println("Bit pattern : 11111111 11111111 11111111 11111111");
for(i = 0 ; i < 10 ; i++) {
a = a >>> i ;
System.out.println("a >>> " + i + " (Zero-fill) bit positions a = " + a +" ");
//System.out.println("Bit pattern : 00000000 00000000 00000000 11111111");
}

NADEEMUDDIN wrote:
a = a >>> 24 ;
SECOND PROGRAM
for(i = 0 ; i < 10 ; i++) {
a = a >>> i ;
System.out.println("a >>> " + i + " (Zero-fill) bit positions a = " + a +" ");
//System.out.println("Bit pattern : 00000000 00000000 00000000 11111111");
}The problem is that in your second program, a gets shifted with i meaning first time is a >>> 0, second time a >>> 1 etc. and all that it's equivalent with a >>> 45 at the end of the loop.
To have the same results some changes must occur:
for(i = 0 ; i < 24 ; i++) {
a = a >>> 1 ;
System.out.println("a >>> " + i + " (Zero-fill) bit positions a = " + a +" ");
//System.out.println("Bit pattern : 00000000 00000000 00000000 11111111");
}So in the final pass (24th) the a = a >>> 24.
Cheers!

Similar Messages

  • Bitwise operators--please explain ?

    I've been reading about bitwise operators, and I get the concept about what they do. My question is why would you ever need an operator like this? When do you need to manipulate memory like this? I can't concieve of a use for it, but obviously there must be one. Just curious--thanks.

    Hi...
    when you have packed different values into one variable...
    hmmm... for example, when you use RGB color system, normally, you have the 3 values of the colors in just one 32 bit integer value, in this format:
    XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
    R G B
    where X = one bit... (an integer is 32 bit size)...
    then, you need bitwise operators for extract the values for each color, something like this:
    int color = something that obtain the value of the pixel...
    int r = (color & 0xFF0000)>>16;
    int g = (color & 0xFF00)>>8;
    int b = color & 0xFF;
    another use of the bitwise operators is in some devices with digital inputs/outputs, where the values of that are given packed in just one integer value (or another type)....
    I hope this helps you...
    ps. sorry for my english...
    EOF

  • How do Bitwise Operators work?

    Hi everybody
    I know a little bit of bitwise operators and I am getting some problems working with them.
    For example, imagine the byte 0x42 (Or 01000010). Now I want to build a long having this byte on the first position starting from the left so I try the following code:
    long l = 0x42 << 56;However, this operation seems to work like if I have written:
    long l = 0x42 << 24That is, the new long is a String of only 32 bits. Why does this command ignore the first 32 bits? Any ideas?

    > On a small tangent, I asked this question yesterday:
    what does this program output?
    Guess, then copy and run to see if you were right.
    public class PartyPretzel {
    public static void main(String[] args) {
    System.out.println(12345 + 5432ll);
    Wauu. I would have bet my hand saying that the result will be 66666 and it is 17777. And the reason for this is....

  • Same report, 2 identical servers, 2 different outputs???

    We have a report that is produced correctly on our Staging server, but when we promote the same report to our Production server (which is a mirror of our Staging server), we get different output. The machines are identical in every respect except for the name. The same queues, fonts, and version of Crystal Report (10.2.3600.0) is installed on both. I wish I could upload the 2 versions of the pdfs that are outputted for you to see the differences, but there doesn't seem to be a way to do that here. Any ideas of what could be causing the discrepancies?

    Hi Amanda,
    Can I back track a bit here?  I would like a bit more clarification on how this is being tested.  From what I understand:
    1)  You have the same application running on 2 different servers which are mirrors of each other. 
    2)  The report is exported to PDF directly, not previewed or printed first. 
    3)  The PDF is opened locally on the client machine. 
    A couple of questions I have: 
    1)  Is the client machine viewing the PDFs from both servers or are these 2 different clients as well?  If the clients are different, then can you try opening the PDF from the second server onto your original client and see if they formatting is the same?  I say this because I want to make sure the Acrobat reader is the same version on both machines and to eliminate the possibility that the PDF is fine but the reader may be the culprit. 
    2)  You've removed the printer in the report I see.  On the client machine, is there default printer installed and is it something other than the Generic Text Driver? 
    3)  Same question as above but on the second server?  A printer is important to Crystal even if you are not printing.  Many years ago if a printer was not installed, the print engine would crash the report when you tried to run it.  That's when the No Printer option was added but that's a different story.  I just needed to stress the importance of having a printer installed. 
    Thanks,
    Brian

  • Bitwise operators in XSLT:-

    Hi ,
    Does XSLT has support for BITWISE operations, If so Can you please help me out of that >
    If not , Is there any other way to apply BITWISE logic to the flow in the BPEL.
    I tried it using Java Embedded activity in the BPEL, but I am getting the following Exception SCAC-50012,tried referring to this Exception, but not able to get the exact view of that error., as this activity in the BPEL doesnt have JAVA editor I am not able to point out the same.

    Hi everybody,
    I have the following queries in JAVA.
    1)Is "Operator Overloading" is nothing but
    but "Method Overloading" in Java?There's no operator overloading in Java. For example + can't be changed to mean something else.
    2)Regarding BitWise Operators, i just wanna have
    have an simple example abt the usage of bitwise
    operators. i.e., in real world where we will be using
    these ?Just one example of many is the use of bitwise XOR in simple encryption/decryption. The scheme is called XOR scrambling.
    byte key = 0x77; // a key byte 0101 0101
    byte any = ......; // any byte to be scrambled
    byte scramble = key ^ any; // the scrambled byte
    byte unscramble = key ^ scramble; // unscramble == any, the original byte is back againIt builds on the fact that if you XOR any byte with a bit pattern (key) two times you get the original byte back again.

  • Different Output of the template from Template Builder and Oracle Apps.

    Hi,
    I have created a template with a page layout of 11" X 17" this template has around 18 columns.
    When i load the XML data and run it from XML Template builder 5.6.2 the output is fine but when I run it through oracle applications i get different output basically the output from oracle applications comes in 7 pages (First page has half page output , 2 nd page has 3/4th page output.....) where as from XML template builder the output comes in 6 Full pages.
    Wher am i going wrong.
    Thanks in Advance.

    The output is in PDF format.

  • Different Output's for PO's

    Is it possible to have different Output options for PO in the backend, like for example if PO is created based on PR coming from SRM SC then the output must be of say type 1, but if the PO is created from the back-end PR or with no connection at all to the PR coming out of SRM then the output must be of type 2??, if yes can some one please tell me how ?? thanks in advance.

    Hi. You could link your reqs from SRM to a new PO doc type in R/3.
    That way the POs from EBP reqs would have a different doc type to other POs created in R/3.
    Then you can have a new output type with a new form and use condition records in MN04 and MN05 to point to different outputs per PO type.
    An even easier way would be to have different pruchasing groups for your reqs from EBP, and base the output type on purchasing group.
    Regards,
    Dave.

  • Ad hoc query - Infoset, after selection it is giving two different output

    Hi All,
    We are facing problem in ad hoc query, after PQAH Ad hoc query, when we go to one infoset, so after making some selection and putting some output field,
    When we click on refresh data button(in lower pane) so it gives only one record, which is incorrect, but when we click on u2018Start Outputu2019 button it gives 3 records those are correct.
    Can anyone tell me, why this is giving different output.(first time 1 record, and second time 3 records) record 3 output is correct.
    Regards,
    Kumar
    Edited by: kumar r12 on Mar 18, 2011 9:00 AM

    Hi Kumar,
    Are you looking at the "Hit List" or the output of the results in the lower pane?  The hit list will only give you the number of persons who will be in your output.  The refresh button should give you a preview of the output. 
    What persons or fields are different or not shown in the preview area vs. the output?  Also, what are the dates for the data?  Are you looking at current data or looking for history?  The output may be showing you history and the preview only current data.  Most concerns with Ad Hoc Query output are related to dates - for the selection and the output. 
    Paul

  • Acrobat DC and XI different Output preview; same setting on the same machine

    Hello,
    I've got an question regarding Output preview
    My sample PDF does have different output preview values on Acrobat DC (100% Black) and Acrobat XI (CMYK values)
    Both use the same setting (Euroscale Coated v2), doc has no PDF/X output intent
    Still..... it's strange that on one Mac the PDF does look different....
    What's going wrong?
    Kind regards

    Numerous fixes went into color display on MacOS for Acrobat DC as well as in Output Preview in general. That having been said, I don't recall any changes that would have resulted in the phenomena you are seeing.
    I assume you were clicking on the “black” circle to get you sample color values? And what do you believe should be the correct values? CMYK=(0,0,0,1) or CMYK=(0.8,0.64,0.67,0.75)?
    If you can post a copy of this file, we can examine it to see what is going on.
                  - Dov

  • Smartform Different output formats in same language

    Hello
    I have a Bulgarian smartform which is translated via SE63 into English.We have a customizing table and according to some fields from there,the customer wants to have the english smartform to have slightly different outputs, no big differences,but for ex some bigger/smaller characters or some fields that should not be displayed.
    How can i do this,because the only way to control this is via se63 that has no such option?
    Thank you

    Look at SE63 translation screen, some constants texts are represented like <F1>пример</ > where <F1> is the character format, so translate it to <F2>example</ > and the text will be printed with another character format.
    But it may be easier to check the language code in the Smartforms itself, especially for text that are not to be printed, (if you don't wont to translate text to initial value) or for full variable text (text item without any constant) that don't appear in the translation screen.
    Regards,
    Raymond

  • Java-puzzlers...Why 2 different outputs for the same line

    Here, why it is giving 2 different outputs for the same set of lines
    Line-1 and Line-2 are both same.But giving 2 different results ???
    /*java-puzzlers*/
    public class Elementary {
        public static void main(String[] args) {
             System.out.println(12345 + 5432l);  /*Line-1: Original statement- didn't modify*/
          System.out.println(12345 + 54321);  /*Line-2: I wrote - I delete 12345 + 54321 and wrote the same thing again*/
    }

    kjshikal wrote:
    one of them is a longkjshikal,
    For the third and final time. Please stop resurrecting old threads like this.
    Thank you for your co-operation.

  • Bitwise Operators .. stupid question ?

    I have a HashMap which contains Strings.. The String are actually numbers.
    I want to use Bitwise operators of and or, xor on them... How so I do it?
    I want to say result = string1 and string2...... I am not sure how stupid this sounds... but I am sure I am too close to it....

    Example answer to your original question, wanna:
    Hashtable<Object, String> ht = new Hashtable<Object, String>();
    ht.put("twenty eight", "28");
    ht.put("five", "5");
    ht.put("twenty", "20");
    System.out.println(Integer.valueOf(ht.get("twenty eight")) & Integer.valueOf(ht.get("five")) & Integer.valueOf(ht.get("twenty")));Which, of course, prints "4" to standard out. You're best off using a Hashtable<Object, Integer>, though.
    In answer to your second question,
    ~ is indeed the compliment operator. E.g:
    System.out.println(1 + ", " + (~1));
    prints "1, -2", as you might expect.

  • Bitwise operators on Long

    Can I operate the bitwise operators e.g. on long?
    i.e.
    long l1;
    long l2 = l1<<32;
    Thanks

    I don't see why not. Have you thought of trying it. It seems like it would be a simple test.

  • Problem with same Container for 2 different outputs

    Hi,
    I am using method set_table_for_first_display to display 2 different output with same container depending upon the selection of radio button. but the problem I am facing is when I click BACK button after dispaying second output and executing first output, it is showing prebious output only. is there any method to handle this problem?
    Regards,
    Nilanjana

    Hi,
    On clicking back use leave to screen 0 in the PAI module of the screen.
    Call screen 100.
    PROCESS BEFORE OUTPUT.
    Logic
    PROCESS AFTER INPUT.
    MODULE USER_COMMAND.
    MODULE USER_COMMAND INPUT.
    IF sy-ucomm EQ 'User command defined for BACK button'.
    LEAVE TO SCREEN 0. "Go back to selection screen
    ENDIF.
    END MODULE.
    Have a look at the method FREE of class cl_gui_alv_grid.
    eg:
    CALL METHOD wcl_alvgrid1->free
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.
    Thanks,
    Vinod.

  • EMU-0404 USB: Using different outputs in abelton?

    Hello Community,
    Can I use different outputs for my tracks in abelton live. I want to root the master-track to one stereo output, and new tracks together to the other outputpair for headphones, to hear the track sperated and NOT on the master, but on the front headphone-out is the same signal as on the output on the back
    When I start Abelton an configurate my in and outputs. I got 4 output-fields activated!
    1 (mono) &amp; 2 (mono) | 1/2 (stereo)
    3 (mono) &amp; 4 (mono) | 3/4 (stereo)
    On the master track i mapped
    Master out 1/2
    Cue Out 3/4
    If i press the headphone-button on a track i can se the signal in cue out 3/4 in the master track, but i cannot hear anything on the headphones. The EMU headphone out on front got the same signal as the outputs on the backside.
    Which output gets the signal?

    0404USB has 4 mono input ports and 4 mono output ports which are 2 analog and 2 digital ports.
    As the headphone output DAC is shared with 2 analog outputs, you can't do what you're describing without routing the digital signal through some external D/A Converter using S/PDIF path.
    IIRC. there's a picture in User's guide showing the signal paths for this device.
    jutapa

Maybe you are looking for