Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Shift - byte[] buf shift

Reply
Thread Tools

Shift - byte[] buf shift

 
 
Roberto Gallo
Guest
Posts: n/a
 
      01-27-2004

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



 
Reply With Quote
 
 
 
 
Thomas Schodt
Guest
Posts: n/a
 
      01-27-2004
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()
 
Reply With Quote
 
 
 
 
Roberto Gallo
Guest
Posts: n/a
 
      01-27-2004
Thank you...

Much easier than doing by hand.



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



 
Reply With Quote
 
Thomas Schodt
Guest
Posts: n/a
 
      01-27-2004
Roberto Gallo wrote:

> "Thomas Schodt" <"news04jan"@\"xenoc.demon.co.uk\"> wrote in message
> news:bv5vu2$h9q$1$(E-Mail Removed)...
>
>>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 >>>).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stringstream: rdbuf()->sgetn(buf, rdbuf()->in_avail()) contentsdiffer from str() whatdoineed2do@yahoo.co.uk C++ 2 02-11-2008 10:20 PM
Read hex string to a buf cppbeginner@gmail.com C Programming 21 02-03-2007 01:06 AM
Not allowed E[] buf = new E[5]; ... ? Red Orchid Java 2 09-26-2005 01:35 AM
how can i get the address of buf which defined as char buf[] = "abcde"; baumann.Pan@gmail.com C Programming 33 06-08-2005 01:03 AM
Is buf[n]++ a lvalue? Stub C Programming 10 11-10-2003 12:46 PM



Advertisments