Not sure if this is relevant to the original question, but I have used
the following logic to convert bytes to integers. This logic assumes
that the data is ASCII similar to what Robert desribed.
-----------------------------------
        public static int toInt(byte[] aBytes) {
                if (aBytes == null || aBytes.length == 0) {
                        return 0;
                }
                if (aBytes.length > 4) {
                        throw new IllegalArgumentException("Number of bytes > 
4");
                }
                int total = 0;
                for (int value : aBytes) {
                        total = total << 8 | (value & 0xFF);
                }
                return total;
        }
-----------------------------------

thanks,
Srikanth

On 4/14/06, Enrique Rodriguez <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> ...
> > For example:
> >
> >             byte[] stringBytes = new byte[length];
> >             buffer.get(stringBytes, 0, length);
> >             char[] stringChars = new char[length];
> >             for (int i = 0; i < stringChars.length; i++)
> >             {
> >                 stringChars[i] = (char) stringBytes[i];
> >             }
> >             return new String(stringChars);
> >
> > Although it looks a bit cumbersome it is five times faster (from my
> > measurements) than constructing the String directly from a byte array.
>
> Thanks!  I needed this for something I'm working on, too.
>
> Enrique
>
>

Reply via email to