Java Hex Calculate toHex(byte[] data, int off, int len)

Here you can find the source of toHex(byte[] data, int off, int len)

Description

to Hex

License

Open Source License

Declaration

public static String toHex(byte[] data, int off, int len) 

Method Source Code

//package com.java2s;
/*/*from w  ww  . j ava  2 s.  co  m*/
 * $Id$
 * 
 * Copyright (c) 2007, Dmitri Trounine.
 * All rights reserved.
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version
 * 2 only, as published by the Free Software Foundation.  
 */

public class Main {
    public static String toHex(byte[] data, int off, int len) {
        StringBuffer s = new StringBuffer();
        for (int i = off; i < off + len; i++) {
            if (i > off) {
                s.append(' ');
            }
            s.append(toHex(0x000000ff & data[i]));
        }
        return s.toString();
    }

    public static String toHex(int x) {
        StringBuffer s = new StringBuffer();
        s.append("0x");
        if (x < 16) {
            s.append('0');
        }
        s.append(Integer.toHexString(0x000000ff & x));
        return s.toString();
    }
}

Related

  1. toHex(byte[] data)
  2. toHex(byte[] data)
  3. toHex(byte[] data)
  4. toHex(byte[] data, int bytesPerGroup)
  5. toHex(byte[] data, int length)
  6. toHex(byte[] data, int perLine, boolean offset)
  7. toHex(byte[] dBytes)
  8. toHex(byte[] digest)
  9. toHex(byte[] digest)