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).

Similar Messages

  • 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...

  • Save As operation Question

    Scenario - I have a web application that generates Excel documents that can be downloaded or opened directly. The web pages are a mixture of both ASP.NET and Classic ASP so the Excel file is actually generated as an HTML table. When a Save or Save As operation
    is done when the .xls file is downloaded a specified file name passed from the web page is used in the save operation. When you open the Excel file after saving Excel displays "The file you are trying to open "filename.xls" is in a different
    format than specified by the file extension...Do you want to open the file now?" informing me that the file is not a true xls file. When you continue with the opening the file it opens normally with no issues.
    Question or Possible issue: Taking one of these files after it has been saved to a location on the computer outside of the download folder, and perform a Save As operation to change the format to a true .xls file the theExisting File Name is not displayed in
    the File Name field. The Save as type defaults to Web Page which is understandable due to how the file is generated.
    I've tried this with actual Excel spreadsheets and the File Name field on the Save As operation is populated with the current name of the file and keeps it even if you change the Save as type.
    Main Question: Is there a setting somewhere in Excel to prevent the loss of the File Name?

    Hi,
    According to your description, the "The file you are trying to open "filename.xls" alert is from a feature called Extension Hardening, and you can find more information about it here. 
    http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
    As you said and tested, Excel will retain the current file name in file name field when we save/save as the file. It's a default behavior. I suppose that the issue may be caused by the Excel that generated by web application.
    I recommend we try the 3 workarounds:
    1. Modify the ASP.NET program and make the file change to new excel format when generated
    Please see the thread:
    http://stackoverflow.com/questions/940045/how-to-suppress-the-file-corrupt-warning-at-excel-download
    2. Use "Office Migration Planning Manager" to convert the XLS to XLSX format.
    The toolkit also contains the Office File Converter (OFC), which enables bulk document conversions from binary to OpenXML formats. 
    Overview on Technet
    Download Link
    3. Use a macro to convert batch of XLS file to XLSX file and retain the file name.
    Sample code:
    Sub ProcessFiles()
    Dim Filename, Pathname, saveFileName As String
    Dim wb As Workbook
    Pathname = "C:\Users\myfolder1\Desktop\myfolder\Macro\"
    Filename = Dir(Pathname & "*.xls")
    Do While Filename <> ""
    Set wb = Workbooks.Open(Pathname & Filename)
    saveFilename = Replace(Filename, ".xlsx", ".xls")
    wb.SaveAs Filename:=Pathname & saveFilename, _
    FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False
    wb.Close SaveChanges:=False
    Filename = Dir()
    Loop
    End Sub
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • 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

  • The Shift operator Question

    Dear sir/madam
    I having question for the shift operator.
    What different between >>> and >> ?
    I have refer to sun tutorial, it state >>> is unsign, what does it mean?
    and last is
    if integer is 13
    what anwer for 13>>8
    is it move for 8 right by position? pls told me in detail
    is it answer same with the 13>>>8 ?
    Thanks for ur solutions

    You can play with the following for a while.
    final public class BinaryViewer{
      final static char[] coeffs = new char[]{(char)0x30,(char)0x31};
    public static String toBinary(int n) {
      char[] binary = new char[32];
      for(int j=0;j<binary.length;j++) binary[j]=(char)0x30;
      int charPointer = binary.length -1;
      if(n==0) return "0";
      while (n!=0){
          binary[charPointer--] = coeffs[n&1];
          n >>>= 1;
    return new String(binary);
    public static void print(int n){
        System.out.print(BinaryViewer.toBinary(n));
        System.out.print("   ");
        System.out.println(String.valueOf(n));
    public static void main(String[] args) throws Exception{
       int n=Integer.MIN_VALUE;//Integer.parseInt(args[0]);
       int m=Integer.MAX_VALUE;//Integer.parseInt(args[1]);
       BinaryViewer.print(n);
       BinaryViewer.print(n>>8);
       BinaryViewer.print(n>>>8);
       System.out.println();
       BinaryViewer.print(m);
       BinaryViewer.print(m>>8);
       BinaryViewer.print(m>>>8);
      System.out.println();
        n=1024;
        m=-1024;
       BinaryViewer.print(n);
       BinaryViewer.print(n>>8);
       BinaryViewer.print(n>>>8);
       System.out.println();
       BinaryViewer.print(m);
       BinaryViewer.print(m>>8);
       BinaryViewer.print(m>>>8);
      System.out.println();
       n=2048;
       m=-2048;
       BinaryViewer.print(n);
       BinaryViewer.print(n>>8);
       BinaryViewer.print(n>>>8);
       System.out.println();
       BinaryViewer.print(m);
       BinaryViewer.print(m>>8);
       BinaryViewer.print(m>>>8);
      System.out.println();
    }

  • Range Operator Question

    Hello all,
    I asked a question yesterday under the title of "Range
    Operator for first 2 letters of item" which was answered promptly and was much appreciated. I have since encountered another problem and would like another example if possible.
    How would I search for all folders under C:\ that start with "Commercial_Global_Trading" through the end of all folders that start with "C"? Can I use a Range Operator for this as well?
    Hopefully it makes sense what I'm asking!
    Thanks!

    Yes it is a bit confusing. Maybe an answer from my previous post will help clear up what I'm asking:
    Using range operators, we can get folders that start with A, B, and C by saying:
    get-childitem 'C:\Folder\[a-c]*'
    We can also get folders that start with Aa, Ab, and Ac by saying:
    get-childitem 'C:\Folder\A[a-c]*'
    What I'm wondering is, is there a way to get all folders in a range, beginning with a specific
    word and then continue through the rest of the range? For example:
    The folder C:\Folder contains the following 6 folders:
    Account
    Commercial
    Commodity
    Commodity_Product
    Conduct
    Finance
    How would I use range operators in get-childitem to return the folders that start with Commodity, and then continue on through the rest of the C's? So the output would be the folders Commodity, Commodity_Product, and Conduct. The folder "Commercial" would
    be excluded from the output. Is this possible using Range Operators and Get-ChildItem?

  • Conditional operator question?

    Hello,
    Quick question, are we not allowed to use the conditional operator this way... see code below:
    char volatile ProgString_[] = "\
    {Fan code} \
    12 <Limit11> [C1_ACM2]_[B1] _AND_ \
    bla bla \
    unsigned char UPC_SYSZ_EndOfTable(unsigned long i){ // Find the double '*' in string
    char volatile *u;
    u = &ProgString_[i];
    if(!(strncmp("*", u, 1))){
    i++;
    u = &ProgString_[i];
    if(!(strncmp("*", u, 1))){
    return TRUE;
    else {
    return FALSE;
    else
    return FALSE;
    void UPC_SYSZ_Parse(){
    unsigned char volatile iOCntr = 0;
    unsigned long volatile i;
    for(i=0; i<200; i++){
    (UPC_SYSZ_EndOfTable(i))?(break):(continue); //<<<<< Invalid expression ??
    I would of used the following compact line:
    (UPC_SYSZ_EndOfTable(i))?(break):(continue);    //<<<<< Invalid expression ??
    to periodically test the end of the string by fetching the "EndOfTable() function and evaluating if the double star is detected.
    If detected, I would break out of the for loop, if not then I would continue.
    Is it possible to do it this way?
    thanks for all help!
    r

    Think of it along the lines of each of the operands of the ternary operator must produce a value (which of course break and continue being statements cannot do).
    Based on your brief example here is what I would do
    for(i=0; i<200; i++){
    if (UPC_SYSZ_EndOfTable(i)) break;
    // doesn't make any sense to put more code down here anyway, so no real point to continue}

  • 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

  • CWMS 1.5 Operational Questions

    Hello All:
    I am looking for some help with my new CWMS 1.5 system.  I have several problems listed below.  If the features aren't in the current release, I am interested if they might be planned for an upcoming release.
    1.  How do you delete a user or a mis-typed email address?
    2.  How do you delete the branding logo?  We uploaded a logo but can't find a way to set it back to default.
    3.  How do you restrict some people to WebEx with desktop sharing and others to just personal audio conference calls?  Looking for some sort of class of service capability.  Might want to also allow Mobile and other features by class as well. 
    4.  How do you generate a report of the Userids, pins, and host/moderator numbers assigned? 
    5.  How do you turn off email notifications?  We want to load a large list of users but when we do it sends everyone an email.  We are trying to stage the system and get ready for testing.
    6.  Is there a way to allow someone from our Service Desk to act as an operator on a call that would be able to mute a line?  Looking for some sort of BigBrother capability.  Should have full access to someones account and all active conference calls.
    7.  Is there a way to get a report of what numbers were dialed?  Looking to determine number of internal versus external callers.
    8.  Why is public access required for IOS functionality?  The IPAD or IPHONE can be on the company local network or connected with a VPN connection.  We don't have IRP installed but IOS should still work.

    Hello David,
    Let me answer some of your questions:
    1. You cannot delete a user profile. If you mis-typed an e-mail address, all you can do is DEACTIVATE the profile. The behavior is the same as in WebEx SaaS.
    2. At this time there is no supported way to delete the company logo using GUI. I am sure there is a way to remove it via CLI, but you would need TAC assistance for this.
    3. At this time, it is not possible to differentiate privilege levels on per user bases. Any changes to capabilities is done on per system basis.
    4. All the available reports are found in the Reports section. There is no such a report that you are looking for. Only available reports that come within Customize Your Report are:
    UserLicenseUtilizationReportForThisMonth.csv
    UserLicenseUtilizationReportForLastMonth.csv
    SystemDowntimeReport.csv
    NetworkBandwidthUtilizationReport.csv
    MeetingReport.csv
    FraudAttemptsReport.csv
    5. At this time, if you are importing users via CSV file, only if you mark the user as INACTIVE during the import (in a csv file under column ACTIVE you mark N for the user profile) the system won't send an e-mail. Once you mark the user as ACTIVE, the system will e-mail the end user.
    6. At this time, only host of the meeting can perform those actions within the WebEx Meeting Room.
    7. There is no such a report in CWMS.
    8. I cannot provide you an answer for this question as this is rooted in product design. Mobile devices require IRP server to be able to join meetings on CWMS.
    I hope any of these answers will help.
    -Dejan

  • 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.

  • Bitwise Operator

    Hi Gurus,
    I am bit poor at math and yes i know bitand is used for binary and operation. But i can't figure out this conversion.
    Here is a flag column values from ts$
    flags   0x40 = COMPRESS
             0x10000 = OLTP Compression
             0x20000 = Columnar Low Compression
             0x40000 = Columnar High Compression
             0x80000 = Archive CompressionAnd here is corrosponding conversion in dba_tablespaces script.
    case when bitand(ts.flags,  65536) = 65536  then 'OLTP'
                      when bitand(ts.flags, (131072+262144)) = 131072
                        then 'QUERY LOW'
                      when bitand(ts.flags, (131072+262144)) = 262144
                        then 'QUERY HIGH'
                      when bitand(ts.flags, (131072+262144)) = (131072+262144)
                        then 'ARCHIVE LOW'
                      when bitand(ts.flags, 524288) = 524288
                        then 'ARCHIVE HIGH'
                      else 'BASIC' end))Now, here are my question
    1. 0x40 & 0x10000 and othere are hexa values Right ?
    2. So what does 65536 means here all other values are multiple (131072) are of this
    3. So, what are we checking here with this kind of bitand(ts.flags, (131072+262144)) thing
    Can someone please explain in simple terms. I searched manuals and other but they give just high level information but not basic.

    decimal 65536 is the same as hexadecimal 10000
    You can test it useing a calculator or SQL
    select to_char(65536,'fmXXXXXX') hexConversion from dual;
    HEXCONVERSION
    10000BITAND is used to test if a certain bit is set or not. For example in your case it is used to test if the bits for ARCHIVE + LOW COMPRESSION are set.
    Hex 10000 in Binary code (not HEX) looks like this
    0x10000  => 0000100000000 .... many 0s
    0x20000  => 0001000000000 .... many 0s
    0x40000  => 0010000000000 .... many 0s
    0x80000  => 0100000000000 .... many 0s Bitand does a binary AND operation on each bit. Therefore it can be used to find out if certain bits are set or not.
    example
    1000111010001
    BITAND
    0000110000000
    0000110000000For each bit the AND operator works like this
    0 AND 0 = 0
    0 AND 1 = 0
    1 AND 0 = 0
    1 AND 1 = 1
    Edited by: Sven W. on Aug 30, 2010 5:45 PM

  • WLS 11g License File Operational Question

    Hello,
    I understand there is no license file anymore with WLS11g download, however of course you need a license for usage of WLS11 in production.
    So I understand it is more a legal issue that you have to buy a license.
    My question is, what do you get if you buy a license for WLS?
    - A file that is technically not used?
    - A letter stating you have bought a license that can be used for a particular CPU?
    I wonder if you still get a file (which does not affect the functionality of WLS) do I have to take care to place in the right location for legal lissues?
    I am thinking of operational guidelines in bigger/big environments.
    - Is there a technical way to check/gurantee in large environmnet by talking to the WLS instances and retrieve the current licensing?
    I guess no one wants to risk running unlicensed instances.
    thanks for your input to this untypical question,
    B.

    If you contact support, there has been discussions going on of making available some type of auditing software to cover the cases that you mention for organizations that want to monitor their compliance and deployments on their own. I'm not sure the status of that effort.
    The license file is no longer even present in 11g at all.

  • LIKE OPERATOR QUESTION

    Hi All,
    Quite simply I don't really understand two things.
    1) How is the LIKE operator is working to return both columns.
    2) When to use the LIKE operator and when to use the relation operator.
    Thanks.
    (CODE)
    SELECT *
    FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
    TO_DATE ('1-Jan-2009') bb FROM DUAL
    WHERE aa LIKE bb
    --returns both columns
    SELECT *
    FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
    TO_DATE ('1-Jan-2009') bb FROM DUAL
    WHERE aa = bb
    --returns nothing
    (/CODE)

    Hi,
    DaveyB wrote:
    Hi All,
    Quite simply I don't really understand two things.
    1) How is the LIKE operator is working to return both columns.The WHERE clause (whether it contains LIKE or anything else) will only control the number of rows: every row will have the same numberr of columns.
    2) When to use the LIKE operator and when to use the relation operator.Use LIKE when you want to use "wildcards" (% or _).
    Use other operators (like =) when you don't have wildcards.
    (CODE)
    SELECT *
    FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
    TO_DATE ('1-Jan-2009') bb FROM DUAL
    WHERE aa LIKE bb
    --returns both columns
    SELECT *
    FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
    TO_DATE ('1-Jan-2009') bb FROM DUAL
    WHERE aa = bb
    --returns nothing
    (/CODE)It's great that you're trying to format your code! I wish everyione did that.
    Use square brackets (&#091; and &#093;) if you want to use &#091;CODE&#093; and &#091;/CODE&#093; tags.
    LIKE operates on strings. Don't use a DATE where a string is required. Do some experiments like the ones you tried just using strings, if you want to see how LIKE behaves.

  • Quick if operator question

    If a and b contain a number each, what should
    if(a>0&&b6=0)be?

    = --> assignment operator
    example:
    a = 0;
    a = a + 1
    // a now equals 1; it doesn't solve the algebraic equation or anything
    == --> comparison operator, returns boolean value
    example:
    if(a == 0)
    // do something
    Now you can correct it.
    theAmerican

Maybe you are looking for