Bitwise XOR Operator

I am going through a certification book, that I have found to have errors. I am not real familiar with bitwise operations, but I have come across one that I think is in error. Can someone confirm or deny whether the following is correct?
00001010
^ 00001000
00001000
Thanks

The problem that I posted here was one of many I have found in the certifcation book called "All In One Java 2 Exam Guide". I see on Amazon.com that there is new version of this book being offered in October.
I would recommend that you avoid this book and its new version. There are errors in text. There are errors in code examples. There are errors in questions. There are errors in the answers to the questions. As many reviewers on Amazon.com noted, this is one of the worst books on the market. There was obviously a rush to market. I can't imagine anyone with any technical knowledge proofread the book.
God Bless America

Similar Messages

  • Perform XOR operation in BPEL 10g

    How can we perform bitwise xor operation in transformations in BPEL 10g.
    As a part of requirement, i need to add xor operation.
    Can anyone help on this.
    Thanks
    Phani

    How can we perform bitwise xor operation in transformations in BPEL 10g.
    As a part of requirement, i need to add xor operation.
    Can anyone help on this.
    Thanks
    Phani

  • How can i do bitwise (binary) operations (AND, OR, XOR)

    I need to do bitwise (binary) operations such as AND, OR, and XOR.  For example, how do I AND 10101000 with 11111000?

    for OR, with 10101000 in A1 and 11111000 in A2, try:
      =1×SUBSTITUTE(A1+A2,2,1)
    Result:  11111000
    and for XOR, try:
       =1×SUBSTITUTE(A1+A2,2,0)
    Result: 1010000  (missing leading 0)
    You can display missing leading zeros by setting the cell's Data Format to 'Numeral System' with Base set to 10 and Places to 8, or turn the result into a string with something like this (assuming the result is in A3):
         =RIGHT("0000000"&A3,8)
    SG

  • Logical XOR operator in T-SQL (SQL Server 2000)

    Hi all....
    I was wondering why SQL Server 2000 lacks a logical XOR operator. Do you have a ready to use function that implements it?
    How can I program one by myself? I know that A XOR B is equivalent to NOT A * B + A * NOT B. So I tried to create this function :
    CREATE FUNCTION XOR
    -- Add the parameters for the function here
    @A BIT,
    @B BIT
    RETURNS BIT
    AS
    BEGIN
    RETURN NOT @A AND @B OR @A + NOT @B
    END
    But it didn't compile.
    How can I pass boolean values as parameters? any other hint?
    Thanks
    Jaime

    I have these two views , one of them hard coded as NULL as it always needs to be NULL. I wanted to union them
    Now the problem is I have to replace those NULLS if I have a value from other VIEW or else NULL ( no change)
    I am getting duplicates of rows with values and NULLS , whereas I needed only records with values
    I need records with values and records without value as NULL . please let me know how to eliminate dups with NULLS
    21
    ARGH
    Bus    
    NULL
    NULL
    NULL
    NULL
    21
    ARGH
    Bus
    66
    781
    HEAVY
    00:00.0
    21
    F1WS
    Ship
    NULL
    NULL
    NULL
    NULL
    21
    HGDD
    car
    NULL
    NULL
    NULL
    NULL
    21
    HGDT
    car
    NULL
    NULL
    NULL
    NULL
    Below is the code :
    --- view having values
    SELECT *
    FROM Table1 AS S INNER JOIN
    Table2 AS P ON S.columnA = P.columnB
    WHERE EXISTS
    (SELECT 1 AS A
    FROM Table2 AS R
    WHERE (S.columnA = columnB))
    GROUP BY ALL
    UNION
    --- views harded coded as NULLS
    SELECT *, NULL AS APR , NULL AS MAY , NULL AS JUN , NULL AS JUL , NULL AS AUG
    FROM Table1 AS S INNER JOIN
    Table2 AS P ON S.columnA <> P.columnB
    WHERE (NOT EXISTS
    (SELECT 1 AS A
    FROM Table2 AS R
    WHERE (S.columnA = columnB) )) OR
    EXISTS
    (SELECT 1 AS A
    FROM Table2 AS R
    WHERE (S.columnA = columnB) )
    GROUP BY ALL

  • Behaviour of the boolean XOR ^ operator

    Dear all
    I have a simple enough requirement for a method to return true if one and only one of four supplied parameters are true. I would have predicted that the XOR operator ^ would make this a very straight forward task thus:
         * @return true if exactly one of the given parameters is true.
        boolean xOrTest(boolean a, boolean b, boolean c, boolean d) {
            if (a ^ b ^ c ^ d) {
                return true;
            return false;
        }but this does not work in the following scenario (remember I want the method to return false because more than one parameter is true).
    System.out.println(xOrTest(false, true, true, true)); infact returns true. My question is, can someone explain why ^ behaves this way and can ^ be used to efficiently meet the requirement?
    Appendix:
    The following scenarios all work as I would expect and print false:
    System.out.println(xOrTest(false, false, true, true));
    System.out.println(xOrTest(false, false, false, true));
    System.out.println(xOrTest(false, false, false, false));
    System.out.println(xOrTest(true, true, true, true));The following scenarios all work as I would expect and print true:
    System.out.println(xOrTest(true, false, false, false));
    System.out.println(xOrTest(false, true, false, false));
    System.out.println(xOrTest(false, false, true, false));
    System.out.println(xOrTest(false, false, false, true));regards
    David

    JoachimSauer wrote:
    I wouldn't care about efficiency in this kind of methods. Only optimize,
    when you find out that this method is indeed a bottleneck, otherwise just
    write a simple implementation (simple implementations are usually easier
    to optimize for the JIT compiler, than "clever" impelementations).I agree with you, and when you recommend to basically "write dumb code", this interview with Brian Goetz crosses my mind: http://java.sun.com/developer/technicalArticles/Interviews/goetz_qa.html
    But given that the prolem at hand is Boolean, why not make a simple straightforward approach:
    !((a & b) | (a & c) | (a & d) | (b & c) | (b & d) | (c & d)), which leads to
    !((a & (b | c | d)) | (b & (c | d)) | (c & d)) or
    boolean xor(final boolean a, final boolean b, final boolean c, final boolean d) {
      return !((a & (b | c | d)) || (b & (c | d)) || (c & d));
    }I consider this an acceptable solution, too.
    EDIT:
    No, not anymore! It may look nice and all, but is not quite XOR... so I apologize for being careless and not double-checking what I wrote (my "xor" returns true even if all arguments are false) -- sorry!
    This should (hopefully) be correct:
    EDIT2:
    <del>[...]</del>
    Aarrgh, but it's still horribly wrong! Made the same mistake twice, now I'll take some time to really think before totally embarrassing myself today...
    But I have to admit that JoachimSauer's solution is indeed simpler and is probably the right choice...
    Message was edited (2x) by:
    oebert: correction
    Message was edited by:
    oebert

  • Bitwise And operator

    If the binaryStrings of two ints "a" and "b" are different lengths will the & operator always return zero? i.e
    int a =8;
    int b =4;
    String binarya = "1000"
    String binaryb = "100"
    System.out.println(8,4); --> 0
    Thanks

    847102 wrote:
    Kayaman wrote:
    There is no "different length", the two parameters will always have the same length. Bitwise AND will work on bytes, shorts, ints and longs, meaning 8-bit, 16-bit, 32-bit or 64-bit "lengths".
    Each resulting bit is 1 if both input bits are 1, otherwise the resulting bit is 0.The answer 8 & 4 = 0Both are ints. Both are 32 bits.
       00000000 00000000 00000000 00001000  // 8
       00000000 00000000 00000000 00000100  // 4
       00000000 00000000 00000000 00000000
    1000
    100That's the same as if, in 2nd grade arithmetic, when you're adding 1000 + 100, you do
       1000
       100
    +_____
       2000Edited by: jverd on Apr 20, 2011 8:35 AM

  • Bitwise shift operator...

    I know this is very basic but I've never done this...
    If I have an object that is an Integer, and I want to increase it by 1, isn't this how you do it?
    Object ob=new Integer(10);
    ob=ob>>1;it tells me that >> operator cannot be applied to object, int
    So what can it be applied to..?

    Ummmm,sadly, no... :(
    I really do lack basic computer skills, I don't know
    a lot about binary and stuff... but how would you do
    what I want to do..?I asked because it's quite a weird code. Just checking.
    OK, so:
    the binary shift operator can only be applied between to ints, that is primitives, no Objects (like Integer is).
    This operator is not used to increase a number, but to shift its bits by one to the right.
    Usage:
    int i,j;
    j = 10;
    i = j >> 1;
    Integer obj = new Integer(10);
    int res = obj.intValue() >> 1;
    Integer resObj = new Integer(res);

  • Bitwise complement operator

    Hi,
    I have an int x = 5;
    0000 0000 0000 0000 0000 0000 0000 0101
    ~x
    converts to:
    1111 1111 1111 1111 1111 1111 1111 1010
    Now, x = -6 WHY????
    I know that the 32th digit represents the -ve sign. How to compute the number "6"?
    Thanks for help.
    gogo

    0000 0000 0000 0000 0000 0000 0000 0000 => +1
    0000 0000 0000 0000 0000 0000 0000 0000 => 0
    1111 1111 1111 1111 1111 1111 1111 1111 => -1
    1111 1111 1111 1111 1111 1111 1111 1110 => -2
    1111 1111 1111 1111 1111 1111 1111 1101 => -3
    1111 1111 1111 1111 1111 1111 1111 1100 => -4
    1111 1111 1111 1111 1111 1111 1111 1011 => -5
    1111 1111 1111 1111 1111 1111 1111 1010 => -6
    Is this what you're wondering?

  • SCJP prep help -- bitwise bad boys?

    Hi,
    I'm studying for SCJP so obviously one of the details I have to brush up on are the oft-unused bitwise operators: & | ^ ~
    I'm wondering if there are any mental techniques to using these in your head. Instead of literally writing out the number in binary, performing the comparison, and then re-converting back to decimal.
    Similar to how in grade school we learn that you can take a shortcut of multiplying two long numbers:
    34563
    x 24
    and do these steps:
    3 * 4 = 12, carry the 1
    6 * 4 = 24, add the 1 is 25, carry the 2
    5 * 4 = 20, add the 2 is 22, carry the 2
    4 * 4 = 16, add the 2 is 18, carry the 1
    3 * 4 = 12, add the 1, it all equals 138252
    next line
    then pad a zero on the right
    3 * 2 = 6
    6 * 2 = 12, carry the 1
    5 * 2 = 10, add the 1 is 11, carry the 1
    4 * 2 = 8, add the 1 is 9
    3 * 2 = 6, it all equals 691260
    altogether the answer is 691260 + 138252 = 829512
    In other words, while it's not feasible to add 34563 to itself 24 times (23 actually), there is a trick to figuring it out. Is there something like that for bitwise operators?
    Thanks.

    Thanks -- I finally collated some good tips a few days after I posted that here, with some help from local LUGgers. I'll post them here for the archives:
    Would you mind posting a summary of the helpful tips, tricks, and
    shortcuts sent your way? I'm rather interested in understanding this
    stuff a little better myself.Sure. In fact, they say you really know something well when you can
    explain it to someone else, and this gives anyone a chance to correct me
    if I'm wrong in what I think I know. Here's some of the things I
    learned, combined with what I had already learned from my book (please
    do correct me if I'm wrong):
    1. The unary bitwise NOT operator (~) has a shortcut, but one which
    only works when two's complement is in effect. On systems in which
    one's complement is in effect, it doesn't work. The shortcut is that
    any number n has a bitwise NOT of -n - 1. So
    ~5 == -6
    ~-12 == 11
    Because I'm fortunate enough to be working in Java where you're writing
    for only one platform (the JVM, which has a spec), I don't have to worry
    about exceptions to this for the test.
    2. Other than the NOT operator, the bitwise operators are binary
    operators, working on pairs of numbers. The bitwise AND operator
    returns a 1 for each pair of bits that are both 1.
    So in the case of
    11001 & 10011
    the result is 10001 (because only the first and last digits are both 1).
    The bitwise OR (|) operator returns a 1 for situations in which either
    pair of bits has a 1.
    So in the case of
    11001 | 10011
    the result is 11011 (because the only place in both numbers where there
    is no 1 is the third digit).
    The bitwise XOR (^) operator returns a 1 for situations in which either
    pair of bits, but not both, has a 1 (hence the name "exclusive OR", or XOR).
    So in the case of
    11001 ^ 10011
    the result is 01010 (because in the first, third, and fifth digits,
    either both numbers are 0 or 1).
    The short circuit operators AND (&&) and OR (||) work just like their
    regular counterparts except they stop evaluating once they "know" the
    result (AND stops evaluating if the first operand is false, and OR stops
    evaluating if the first operand is true).
    3. So my original question, "does anyone know any mental shortcuts for
    working with bitwise operators", should have been phrased as "does
    anyone know any mental shortcuts for converting decimal numbers to
    binary". The answer, which a couple of people provided, was that it's
    much easier to convert to binary (even if only in your head) when you
    are working from octal or hexadecimal, and that it's not too difficult
    to convert from decimal to octal or hexadecimal.
    Several ways were suggested:
    a) Convert the number to hex, then do the comparison a byte at a time in
    your head using a table:
    & 0x01 0x02 ... 0xff
    0x01 0x01 0x00 0x01
    0x02 0x00 0x02 0x02
    0xff 0x01 0x02 0xff
    b) Convert the number to octal using a simple recursive divide-by-eight
    solution:
    divide the number by eight, store the remainder as the low bit depth
    (rightmost number), then repeat the process with the quotient.
    123 / 8 = 15 remainder 3 -- 3 is rightmost digit (3)
    15 / 8 = 1 remainder 7 -- 7 is next to 3 (73)
    we don't divide 1 by 8 -- 1 is next to 7 (173)
    so 123 in octal is 0173
    From octal it's much easier to see the binary form of the number:
    1 7 3
    001 111 011
    And from binary it's much easier to do a bitwise calculation.
    c) Another way to convert to binary is to simply keep dividing by two
    and assigning 1 if there's a remainder and 0 if there isn't, then read
    in reverse to get the binary number:
    <quote>
    If a number is even, dividing it by 2 will have 0 remainder.
    If it is odd, dividing it by 2 will have a 1 remainder. Dividing
    by 2 is so easy that I, at least, can just write down a column of
    successive halvings, along with 1s and 0s for their oddness.
    459 1
    229 1
    114 0
    57 1
    28 0
    14 0
    7 1
    3 1
    1 1
    Reading from bottom to top, we again get 111001011. In this
    presentation you stop when the quotient is 1, since you've already
    written down the remainder that you'd get by dividing 1 by 2 when
    you write down the oddness. Remainder when dividing by 2 is easier
    than quotient.
    </quote>
    d) A final useful tip mentioned: as long as x is not zero,
    x & -x
    will always evaluate to a power of two, which means only one bit is set
    in the number (the least significant of the bits of x that were 1s).
    4. And everyone agreed that it's foolish to do these kinds of
    computations in your head when there's no good reason not to use a
    computer to do it. My personal preference is to use Python since the
    interactive interpreter works just like a calculator, though any
    scripting language should probably be able to handle the calculations.
    (Here's a quick sample:)
    |$ python
    |Python 2.2.2 (#1, Dec 31 2002, 12:24:34)
    |[GCC 3.2 20020927 (prerelease)] on cygwin
    |Type "help", "copyright", "credits" or "license" for more information.
    |>>> 12 & 14
    |12
    |>>> 12 | 14
    |14
    |>>> 12 ^ 14
    |2
    |>>> ~12
    |-13
    |>>> myResult = 0x5422CA66 & 458
    |>>> myResult
    |66
    |>>> hex(myResult)
    |'0x42'
    (hey, it wouldn't be a LUG without a little evangelism, would it? :)
    Much thanks to Bill, Jason, Kevin, and YATArchivist.
    Erik

  • Bitwise functions in grapher?

    hi there. i want to graph a function that has a bitwise xor operator. the help was no help. how do i do it?
    for reference, here's the function i want to graph (in c notation, hence the ^ is bitwise xor instead of exponent):
    int x, y;
    y = x + 10000 + 200*(x^11025);

    Hi, have you parused the list of built in functions, I can see none that would suffice, yet did not investigate all the ones I didn't know what they meant.

  • Invalid operands to binary ^ (have 'double' and 'double')

    Hi all,
    I've been trying to make some calculus like
    double a, b, c;
    b = 0.3;
    c =0.35;
    a = b^c;
    but I get this error message: *"Invalid operands to binary ^ (have 'double' and 'double')"*. Does anybody know how to solve this?
    Thanks in advance!

    Yes I think Ray hit the nail on the head. It looks as if you wanted to perform and exponentiation operation, not a bitwise operation. So, just to expand on Ray's answer a bit, the carrot symbol (^) that you used in your statement is, in C, the bitwise XOR operator, and has nothing to do with exponentiation. There are numerous bitwise operators in C (bitwise AND (&), bitwise OR (|), bitwise XOR (^)), and they all deal with manipulating bits of data. If you were, in fact, trying to raising b to the power of c and assign that value back to a, then Ray's post was the perfect answer as to how to do that.
    Many programmers that are new to C, especially ones coming from a language such as Visual Basic, where the carrot symbol is used for exponentiation operations, naturally try to use the same symbol for the same purpose in C, and are surprised to find that it doesn't do what they expected (understandably). As mentioned, this is because, in C, there is no exponentiation operator, and the carrot symbol does something completely different and unrelated to exponentiation. However, C does provide a predefined function in its standard library for exponentiation, and it is called the pow() function, which takes two double-typed arguments (the first is the number being risen and the second is the power that it is being raised to), and returns the result as a double. To use this function, all you have to do is write an include directive at the top of the file that you will be using the function in that tells the preprocessor to include the file math.h. See RayNewb's post for a solid example of how all this stuff would look in your source code, and, as he mentioned, open your Terminal and type in +man math+ or, for this particular function, +man pow+ to find out more about how this function works (you can page through the information with the spacebar or scroll down with the down arrow).
    Hope this was of some help for you, and best of luck with everything!

  • 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

  • XOR (Exclusive OR logical operator)

    Does such a thing exist in SAP ? Do I have something else other than AND and OR as logical operators (like XOR in other languages ? bitwise operators won't help, since I need them in queries).
    Thanks
    Avraham

    Hi Avraham,
    I've found this thread while Googling but not with a satisfying answer, so I researched a bit myself and came up with a solution I prefer:
    Use the BIT-XOR operator in combination with the boolx( bool = log_exp bit = bit ) function. I append a simple example to demonstrate how I'm using it now.
    DATA: is_day TYPE x LENGTH 1 VALUE '01', " it's day
           is_night TYPE x LENGTH 1 VALUE '01', " it's night
           hex_true TYPE x LENGTH 1 VALUE '01'.
    IF boolx( bool = hex_true EQ is_day bit = 8 )
         BIT-XOR boolx( bool = hex_true EQ is_night bit = 8 ) EQ hex_true.
       " EVERYTHING fine - is_day XOR is_night is true
       " not in this example
    ELSE.
       " ERROR - can't be is_day AND is_night at same time (or none of both)
    ENDIF.
    For more information on the topic, please view the boolc, boolx - Boolean Functions F1 Help page in your SAP system.
    Happy Coding
    Daniel

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

  • Is there a bitwise tutorial

    Good day. I want to know more about bitwise logic. I understand in Java what the bitwise operands do. What I can't seem to find is instruction on when you would want to use them. I tend to see them used rarely in code examples. Is bitwise manipulation out dated?
    All omy Googling simply returned examples of bitwise logic but not what I am looking for. I guess I need bit 101.
    Thanks.

    . What I can't seem to find is instruction on when
    you would want to use them. I tend to see them used
    rarely in code examples. Is bitwise manipulation out
    dated? its not outdated at all, the lower programing languages use them a lot more though then higher languages like java though. the advantage of them is that they are incredibly fast, a processor can do a bit shift or xor operation easily while things like a multiplication is very slow and complicated. If your looking for a java example look at the Random class though. Id suggest just learning simple binary operations(add,subtract), after that it takes about 20 minutes to learn bitwise operations. simple uses are like using a bitshift instead of *2 as if its something thats repeated a lot it can help with performance, although i think the compiler may pick this up.
    In java it is not necessary to learn this, but it can be a fun thing to make ur code hard to read(hey, its hard to write right?) or give different options for doing the same thing.

Maybe you are looking for