Results 1 to 4 of 4
  1. #1
    Dogbert1 is offline Member
    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    Default ^ on bytes gets errors in one program, not another.

    First post - I think this is pretty easy, as I'm not too familiar with java.

    I have one code that creates some bytes and uses the ^ (xor) operation on them:

    public static void main(String[] args) {
    int bit1 = 0x3;
    int bit2 = 0xc;
    int bit3;
    byte a = 0;
    byte b = 1;
    byte c;
    bit3 = bit1 | bit2;
    c = (byte) (a^b);
    System.out.println(bit3);
    System.out.println(c);
    }

    It works correctly and outputs exactly what I want.

    My other code includes this:

    public byte FFMul(byte a, byte b) {
    byte aa = a, bb = b, r = 0, t;
    while (aa != 0) {
    if ((aa & 1) != 0)
    r = (byte)(r ˆ bb);
    t = (byte)(bb & 0x80);
    bb = (byte)(bb << 1);
    if (t != 0)
    bb = (byte)(bb ˆ 0x1b);
    aa = (byte)((aa & 0xff) >> 1);
    }
    return r;
    }

    The above gets the message "Syntax error on token "ˆ", invalid AssignmentOperator"
    I have no idea why, what am I overlooking? I use eclipse as my IDE.
    Thanks for the help.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,804
    Rep Power
    5

    Default Re: ^ on bytes gets errors in one program, not another.

    You must have pasted that second snippet of code in from somewhere because it is using an invalid caret symbol (^) for XOR. Try removing it and retyping.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: ^ on bytes gets errors in one program, not another.

    Good eye, Jim.

    OP: here's your caret next to a proper caret.

    ˆ^
    Get in the habit of using standard Java naming conventions!

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,804
    Rep Power
    5

    Default Re: ^ on bytes gets errors in one program, not another.

    Actually, in all honestly, it is Eclipse that has a good eye. I pasted it in and noticed it was different when I retyped it. But thanks just the same. :)

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Errors at my program
    By lineker in forum Apache Maven
    Replies: 1
    Last Post: 07-23-2013, 09:29 PM
  2. How do I fix this program (2 errors)?
    By Logik22 in forum New To Java
    Replies: 17
    Last Post: 07-17-2011, 10:04 PM
  3. Help with some errors in my program
    By kbud123 in forum Java Applets
    Replies: 5
    Last Post: 05-11-2011, 06:08 AM
  4. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  5. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-09-2008, 12:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •