Java Base Encode toBase16(byte[] data)

Here you can find the source of toBase16(byte[] data)

Description

to Base

License

Open Source License

Declaration

public static String toBase16(byte[] data) 

Method Source Code

//package com.java2s;
/*  Copyright (C) 2009 Mobile Sorcery AB
    //from  w w w.j a v  a2  s  .c o  m
This program is free software; you can redistribute it and/or modify it
under the terms of the Eclipse Public License v1.0.
    
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License v1.0 for
more details.
    
You should have received a copy of the Eclipse Public License v1.0 along
with this program. It is also available at http://www.eclipse.org/legal/epl-v10.html
*/

public class Main {
    public static final char[] BASE16_CHARS = "0123456789ABCDEF".toCharArray();

    public static String toBase16(byte[] data) {
        return toBase16(data, 0, data.length);
    }

    public static String toBase16(byte[] data, int offset, int length) {
        char[] result = new char[length * 2];
        for (int i = 0; i < length; i++) {
            result[2 * i] = BASE16_CHARS[(data[offset + i] >> 4) & 0xf];
            result[2 * i + 1] = BASE16_CHARS[data[offset + i] & 0xf];
        }

        return new String(result);
    }
}

Related

  1. toBase(long startMillis, long currentMillis, long baseMillis)
  2. toBase10(final String base62)
  3. toBase10(int[] arr)
  4. toBase10(int[] arr)
  5. toBase10SuffixedString(long n)
  6. toBase16(int[] arr)
  7. ToBase16(StringBuilder str, byte[] data)
  8. toBase2(byte b)
  9. toBase26(int number)