Shift - byte[] buf shift

Discussion in 'Java' started by Roberto Gallo, Jan 27, 2004.

  1. Hi,

    How can I shift or roll a byte array buffer say,

    byte buf[] = byte[16];

    So that I would have the same effect as the "<<" operator in C over a
    Int.

    I want to left shift a 16 byte word in bitwise steps.

    Thank you,

    Roberto.
    ..
    Roberto Gallo, Jan 27, 2004
    #1
    1. Advertising

  2. Roberto Gallo wrote:

    > Hi,
    >
    > How can I shift or roll a byte array buffer say,
    >
    > byte buf[] = byte[16];
    >
    > So that I would have the same effect as the "<<" operator in C over a
    > Int.
    >
    > I want to left shift a 16 byte word in bitwise steps.


    You can use
    java.math.BigInteger(byte[])
    BigInteger.shiftLeft() and BigInteger.shiftRight()
    Thomas Schodt, Jan 27, 2004
    #2
    1. Advertising

  3. Thank you...

    Much easier than doing by hand.



    "Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
    news:bv5vu2$h9q$1$...
    > Roberto Gallo wrote:
    >
    > > Hi,
    > >
    > > How can I shift or roll a byte array buffer say,
    > >
    > > byte buf[] = byte[16];
    > >
    > > So that I would have the same effect as the "<<" operator in C over

    a
    > > Int.
    > >
    > > I want to left shift a 16 byte word in bitwise steps.

    >
    > You can use
    > java.math.BigInteger(byte[])
    > BigInteger.shiftLeft() and BigInteger.shiftRight()
    Roberto Gallo, Jan 27, 2004
    #3
  4. Roberto Gallo wrote:

    > "Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
    > news:bv5vu2$h9q$1$...
    >
    >>Roberto Gallo wrote:
    >>> How can I shift or roll a byte array buffer say,
    >>>
    >>> byte buf[] = byte[16];
    >>>
    >>> I want to left shift a 16 byte word in bitwise steps.

    >>
    >>You can use
    >>java.math.BigInteger(byte[])
    >>BigInteger.shiftLeft() and BigInteger.shiftRight()

    >
    > Thank you...
    >
    > Much easier than doing by hand.


    Note that shiftRight() keeps and propagates the sign bit,
    like java >> (as opposed to java >>>).
    Thomas Schodt, Jan 27, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Red Orchid
    Replies:
    2
    Views:
    362
    Mike Schilling
    Sep 26, 2005
  2. Stub

    Is buf[n]++ a lvalue?

    Stub, Nov 7, 2003, in forum: C Programming
    Replies:
    10
    Views:
    632
    Christopher Benson-Manica
    Nov 10, 2003
  3. Replies:
    33
    Views:
    877
  4. Read hex string to a buf

    , Jan 31, 2007, in forum: C Programming
    Replies:
    21
    Views:
    792
    Kenny McCormack
    Feb 3, 2007
  5. Replies:
    2
    Views:
    1,391
Loading...

Share This Page