Java Byte Array Convert To bytes_to_sbuf(byte[] data, int offset, int length, StringBuffer buf)

Here you can find the source of bytes_to_sbuf(byte[] data, int offset, int length, StringBuffer buf)

Description

bytetsbuf

License

Open Source License

Declaration

public static void bytes_to_sbuf(byte[] data, int offset, int length,
            StringBuffer buf) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .  j av a  2 s .  com
 * Copyright (c) 2001-2003 Regents of the University of California.
 * All rights reserved.
 *
 * See the file LICENSE included in this distribution for details.
 */

public class Main {
    private static final char[] digits = { '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static void bytes_to_sbuf(byte[] data, int offset, int length,
            StringBuffer buf) {
        bytes_to_sbuf(data, offset, length, false, buf);
    }

    public static void bytes_to_sbuf(byte[] data, int offset, int length,
            boolean pretty, StringBuffer buf) {
        int size = 2 * length;
        size += (size / 8) + (size / 64);
        int low_mask = 0x0f;
        int high_mask = 0xf0;
        byte b;

        int j = 0;
        for (int i = offset; i < (offset + length); ++i) {
            b = data[i];
            buf.append(digits[(high_mask & b) >> 4]);
            buf.append(digits[(low_mask & b)]);
            if (pretty) {
                if (j % 4 == 3)
                    buf.append(' ');
                if (j % 32 == 31)
                    buf.append('\n');
            }
            ++j;
        }
    }
}

Related

  1. bytes2IPV4(byte[] addr, int offset)
  2. bytes2nibbles(byte[] bytes)
  3. bytes2unique(byte[] daten, int offset)
  4. Bytes4ToInt(byte abyte0[], int offset)
  5. Bytes8ToLong(byte abyte0[], int offset)
  6. bytes_to_short(byte[] buf, int offset)
  7. bytes_to_str(byte[] data)
  8. bytesToAlphaNumeric(byte[] number)
  9. bytesToAsciiMaybe(byte[] data)