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™ Tutorial - A practical guide for programmers
The Java™ 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

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

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

  • Binary operations in Java

    Hi,
    are there any binary operations in Java like '&' in C? I didn't found any information in the API description.
    Thank u.

    You didn't find them from the API since they are a feature of the language. Try the langspec instead: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5228

  • 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

  • OSB11134:the service is not testable since all its operations require Java

    I was trying to Invoke the OSB Proxy service from weblogic Launch Test Console....but "Launch Test Console" icon is disabled.
    it shows the message *"the service is not testable since all its operations require Java arguments""* when I move cursor on top of the icon
    I am using OSB 11.1.3.4.
    Can some one help on this?
    Thanks in Advance.
    AB

    Export your project and send the exported jar to my id. By default, the name of exported jar is sbconfig.jar
    http://download.oracle.com/docs/cd/E17904_01/doc.1111/e15867/import_export.htm#CIHHEJFJ
    Regards,
    Anuj

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

  • 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

  • Command line operations in java

    hi there,
    is it possible to create a java program that can perform a specified command line operation?
    regards

    hi there,
    is it possible to create a java program that can
    perform a specified command line operation?
    regardsYes, thats what the String[] args in public static void main(String[] args) is for.

  • Invoke a FTP "Get File" operation throws java.lang.ClassCastException:

    Hi there,
    I am working on a very simple sample project that will pull the file from a ftp site. I create a partner link with FTP adpater with "Get File" operation.
    When I deploy and run the SIMPLE project, it throws the following exception.
    I am wondering if any of you experienced the same problem and how to resolve the issue. Your help will be greatly appreciated.
    Here is the error message:
    <messages><input><Invoke_1_Get_InputVariable><part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Root-Element"><Root-Element xmlns="http://TargetNamespace.com/ftp_service"/>
    </part></Invoke_1_Get_InputVariable></input><fault><bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>file:/C:/product/10.1.3.1/OracleAS_1/bpel/domains/default/tmp/.bpel_FTPProcess2_1.0_709914d835a81c407ed668866e080b9e.tmp/ftp_service.wsdl [ Get_ptt::Get(Root-Element) ] - WSIF JCA Execute of operation 'Get' failed due to: Could not instantiate InteractionSpec oracle.tip.adapter.ftp.inbound.FTPActivationSpec due to: oracle.tip.adapter.ftp.inbound.FTPActivationSpec; nested exception is:
         java.lang.ClassCastException: oracle.tip.adapter.ftp.inbound.FTPActivationSpec; nested exception is:
         org.collaxa.thirdparty.apache.wsif.WSIFException: Could not instantiate InteractionSpec oracle.tip.adapter.ftp.inbound.FTPActivationSpec due to: oracle.tip.adapter.ftp.inbound.FTPActivationSpec; nested exception is:
         java.lang.ClassCastException: oracle.tip.adapter.ftp.inbound.FTPActivationSpec</summary>
    </part><part name="detail"><detail>org.collaxa.thirdparty.apache.wsif.WSIFException: Could not instantiate InteractionSpec oracle.tip.adapter.ftp.inbound.FTPActivationSpec due to: oracle.tip.adapter.ftp.inbound.FTPActivationSpec; nested exception is:
         java.lang.ClassCastException: oracle.tip.adapter.ftp.inbound.FTPActivationSpec</detail>
    </part></bindingFault></fault></messages>

    Take a look at the stack trace, it shows you exactly where the error is coming from:
    java.lang.ClassCastException: org.theclass.candidate.view.SearchForm
    org.theclass.candidate.view.CandidateListAction.execute(CandidateListAction.java:41)Line 41 in your CandidateListAction.
    Probably it is failing on a cast of your action form.
    Taking a closer look at your struts-config, you are "chaining" actions.
    Your AddCandidateAction uses the candidateForm, and forwards to CandidateListAction.do
    Your CandidateListAction uses the searchForm.
    That will be the cause of your class cast exception.
    <action path="/Add"
      name="candidateForm"
      type="org.theclass.candidate.view.AddCandidateAction"
      validate ="true"
      input="/jsp/addcandidate.jsp">
      <forward name="success" path="/CandidateList.do"/>
    </action>
    <action path="/CandidateList"
    type="org.theclass.candidate.view.CandidateListAction"
    name="searchForm"
    scope="request" >
    <forward name="failure" path="/jsp/list.jsp"/>
    <forward name="success" path="/jsp/candidatelist.jsp"/>
    </action>Check out: http://struts.apache.org/1.x/faqs/newbie.html#chaining
    Solutions?
    - don't chain actions ;-)
    - use the same action form for both actions (possible?)
    - make the actionForward a "redirect" one. That means a new request, and losing any request parameters/attributes but should prevent this class cast exception.
    Hope this helps,
    evnafets

  • How to overload = operator in Java?

    Like String s = "somestring" or Integer i=10, how to develop a class with '=' operator overloaded?
    For example
    MyClass obj = 12.3f;(similar to Float class)

    I understand the answer. But how are these classes
    like String, Integer and other wrapper classes built
    for = operator overloading? Is this accomplished
    using native code?It's just how the language is defined. [url http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html]The JLS defines how these operators are required to behave. The compiler interpets them as per the JLS, to generate the proper bytecodes.

  • Opera 9, Java, and NY Times Sudoku

    I'm having a hard time loading the NY Times Sudoku page with Opera 9 under Arch Linux. It is obviously a Java problem, and I don't seem to have this problem under Fedora Core 5 running jre 1.5.0 there.
    To find that page, load nytimes.com, then choose the Crossword/Games link in the left column. Then choose the Sudoku link in the body of the page.
    My experience under Arch is that the page either locks up Opera 9 or crashes it.

    Titus wrote:
    in extra repo there is 9.02 build
    extra/opera 9.0-2 The Opera web browser
    That's opera 9.0 but the pkg has pkgrel 2, you're kinda confused
    A package of the weekly build is here

  • I want a delete operator in Java. Why not?

    The idea is simple: when I tell "delete some_object;" the system checks if the object can be deleted.
    a) Object is not referenced by any other objects out of the reference cycle *=>* some_object object calls its destructor and then it is deleted, and the same should happen to all objects in the reference cycle. The reference some_object is set to null, as operator delete returns null.
    b) Object is referenced by some other objects, which are not in a cycle of references, ending up at the some_object object itself *=>* some_object object is not deleted (destructor is not called), but the reference some_object is set to null (operator delete returns null) and the reference count of the some_object object (in the system) is decreased by 1.
    Easy.
    Why not?

    grinice wrote:
    b) Object is referenced by some other objects, which are not in a cycle of references, ending up at the some_object object itself *=>* some_object object is not deleted (destructor is not called), but the reference some_object is set to null Makes no sense. There can be multiple references to a given object, and you don't always own all of them. If you want to set one to null, you can already do that with ref = null;
    Easy.If it's that easy, create your own language that does it.
    Why not?Why?

  • ~ operator in java

    Can you show me example how to use this operator?

    This is a result of using 2's complement notation so that negative numbers can be represented. A signed number starts with 0 for positive numbers and 1 for negative numbers. To change sign, invert the bits and add 1:
    127 is 0111 1111
    3 is 0000 0011
    2 is 0000 0010
    1 is 0000 0001
    0 is 0000 0000
    -1 is 1111 1111
    -2 is 1111 1110
    -3 is 1111 1101
    -4 is 1111 1100
    -128 is 1000 0000
    Here's more information:
    http://courses.cs.vt.edu/~cs1104/BuildingBlocks/Chapter4.070.htm

  • Bitwise operator: (010|4)

    Executing the following code results in "12". I do not understand why?
    public class Test {
        public static void main(String[] args) {
            System.out.println(010|4);
    }From what I understand, the answer should be 6. What is wrong with my below logic?
    010 = 2
    100 = 4
    110 = 6
    Thanks!

    You can check out the JLS - go here:
    http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html
    And look at section 3.10.1
    There's no way to explicitly enter a base 2 digit (that I know of) - you can specify it as base 16 by prepending with a 0x, or octal by prepending with a 0. You could use the Integer.parseInt(value, radix) method to do this by passing in the binary digit string and a radix of 2, as int value = Integer.parseInt("010", 2)I hope that helped
    Lee

Maybe you are looking for

  • How to Combine Forms with .PDF files?

    Hello. Several employees at my company frequently generate reports which are then edited in Acrobat 7. Life was good in the days of Acrobat 5. Then something changed between Acrobat 5 and 6, making this virtually impossible. Then along came Acrobat 7

  • How do I add a map of a trip to an idvd ?

    I want to make an idvd of a river cruise and add a map to the dvd.  how do I find a map and add it to show the locacion stops of the cruise?

  • Lenovo Twist many problems

    Bought the new twist about 6 weeks ago. it was down for 3 weeks for a hard drive replacement. It is the i7 with 500G HDD and 8G ram absolutely love the style and feel but the little problems are overwhelming. I am ready to send it back as I dont real

  • Issue while migrating from devlopement to test environment

    Hi All, I have devloped ODI packages to load data from Oracle table,Text to Hyperion Essbase.Its successfully running on devlopement environment. To migrate this on test environment,First I imported Master repository (By importing Zip).Which is succe

  • Checksum (4 characters)

    Hello everyone, I have a serial device with a message-based communication, where it's used 4-characters checksum at the end of message (command). For example command: "START " (space is included at the end), in ASCII: "83 84 65 82 84 32", so the sum