Java ByteBuffer to Hex toHexString(ByteBuffer bb)

Here you can find the source of toHexString(ByteBuffer bb)

Description

to Hex String

License

LGPL

Declaration

public static String toHexString(ByteBuffer bb) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;

public class Main {
    private static final String HEXES = "0123456789ABCDEF";

    public static String toHexString(ByteBuffer bb) {
        ByteBuffer buffer = bb.duplicate();
        StringBuilder hex = new StringBuilder();
        while (buffer.hasRemaining()) {
            byte b = buffer.get();
            hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F)));
        }/*  ww  w  . ja va2s  .c om*/
        return hex.toString();
    }

    public static String toHexString(int[] raw) {
        StringBuilder hex = new StringBuilder();
        for (int b : raw) {
            hex.append(HEXES.charAt((b & 0xF000) >> 12)).append(HEXES.charAt((b & 0x0F00) >> 8))
                    .append(HEXES.charAt((b & 0x00F0) >> 4)).append(HEXES.charAt((b & 0x000F)));
        }
        return hex.toString();
    }
}

Related

  1. toHex(ByteBuffer buf)
  2. toHex(ByteBuffer buffer)
  3. toHex(ByteBuffer data)
  4. toHexStr(final ByteBuffer data)
  5. toHexStream(ByteBuffer data)
  6. toHexString(ByteBuffer bb)
  7. toHexString(ByteBuffer bb, boolean withSpaces)
  8. toHexString(ByteBuffer buffer)
  9. toHexString(ByteBuffer buffer)