Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Shift - byte[] buf shift (http://www.velocityreviews.com/forums/t130755-shift-byte-buf-shift.html)

 Roberto Gallo 01-27-2004 03:10 PM

Shift - byte[] buf shift

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

 Thomas Schodt 01-27-2004 03:25 PM

Re: Shift - byte[] buf shift

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 01-27-2004 03:34 PM

Re: Shift - byte[] buf shift

Thank you...

Much easier than doing by hand.

"Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
news:bv5vu2\$h9q\$1\$8300dec7@news.demon.co.uk...
> 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 01-27-2004 04:26 PM

Re: Shift - byte[] buf shift

Roberto Gallo wrote:

> "Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
> news:bv5vu2\$h9q\$1\$8300dec7@news.demon.co.uk...
>
>>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 >>>).

 All times are GMT. The time now is 02:32 AM.