Results 1 to 3 of 3
  1. #1
    NewJavaBean is offline Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    5
    Rep Power
    0

    Default Bitwise operations with long

    Hi,

    how to perform bitwise operations upon a variable with the type long.
    I'm searching for ways to get single bits out of the number to work with their values(0,1).
    I also have to shift new bits into this order of bits, which should be implemented as a kind of register.


    How to do that?

    Greetings :)

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    is the Long.byteValue() method of any use to you?

    Long (Java 2 Platform SE v1.4.2))

  3. #3
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default MSB test of 64 bit value

    A long is 64 bit in length.

    Bitwise operations are

    "&" for "AND"
    "|" for "OR"
    "^" for "XOR"
    "~" for "NEGATE" (I don't recall if it's 2's complement.)

    Research representing values using Hex Notation.

    The msb for a 64 bit value is represented as:

    "0x80000000"

    Your test of the 64th bit might be:

    Java Code:
    public boolean getLongMSB(long val){
      boolean results;
      results = val & 0x80000000;
      return results;
    }

    or

    Java Code:
    public boolean getBit64(long val){
      boolean results;
      results = val & 0x80000000;
      return results;
    }
    or maybe

    Java Code:
    public boolean getBit64(long val){
      return val & 0x80000000;
    }

Similar Threads

  1. forcibly terminating io operations
    By arnab321 in forum CLDC and MIDP
    Replies: 2
    Last Post: 11-15-2008, 08:51 PM
  2. Illegal Arithmetic Operations?
    By Cruor in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 04:46 PM
  3. Using the bitwise operators
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:39 PM
  4. String operations..
    By sireesha in forum New To Java
    Replies: 4
    Last Post: 12-14-2007, 02:04 AM
  5. Uses unchecked or unsafe operations message
    By Robbinz in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 10:56 PM

Posting Permissions

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