Java Hex Calculate toHexadecimealString(byte[] data, int length, boolean uppercase)

Here you can find the source of toHexadecimealString(byte[] data, int length, boolean uppercase)

Description

to Hexadecimeal String

License

Apache License

Declaration

static public String toHexadecimealString(byte[] data, int length, boolean uppercase) 

Method Source Code

//package com.java2s;
/**//from  www. ja v  a 2 s . c  o m
 * Sapelli data collection platform: http://sapelli.org
 * 
 * Copyright 2012-2016 University College London - ExCiteS group
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

public class Main {
    static public String toHexadecimealString(byte[] data, int length, boolean uppercase) {
        StringBuffer bff = new StringBuffer();
        // zero padding:
        for (int i = data.length; i < length; i++)
            bff.append("00");
        // the bytes:
        for (byte b : data)
            bff.append(String.format("%02" + (uppercase ? "X" : "x"), b));
        return bff.toString();
    }

    static public String toHexadecimealString(byte[] data, int length) {
        return toHexadecimealString(data, length, true);
    }

    static public String toHexadecimealString(byte[] data, boolean uppercase) {
        return toHexadecimealString(data, data.length, uppercase);
    }

    static public String toHexadecimealString(byte[] data) {
        return toHexadecimealString(data, true);
    }
}

Related

  1. toHexadecimal(byte[] digest)
  2. toHexadecimal(byte[] digest)
  3. toHexadecimal(final byte[] array)
  4. toHexadecimal(final byte[] in)
  5. toHexadecimal(final byte[] message)
  6. toHexArray(byte[] binary)
  7. toHexaString(byte[] data)
  8. toHexaString(int value)
  9. toHexByte(byte b)