Content byte[] array to hex string
public class Main {
public static final String toHexString( byte[] res )
{
StringBuffer buf = new StringBuffer( res.length << 1 );
for ( int ii = 0; ii < res.length; ii++ )
{
String digit = Integer.toHexString( 0xFF & res[ii] );
if ( digit.length() == 1 )
{
digit = '0' + digit;
}
buf.append( digit );
}
return buf.toString().toUpperCase();
}
}
import java.security.SecureRandom;
import java.util.Random;
public class Main
{
public static String toHexString( byte[] bytes )
{
StringBuffer sb = new StringBuffer( bytes.length*2 );
for( int i = 0; i < bytes.length; i++ )
{
sb.append( toHex(bytes[i] >> 4) );
sb.append( toHex(bytes[i]) );
}
return sb.toString();
}
private static char toHex(int nibble)
{
final char[] hexDigit =
{
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
return hexDigit[nibble & 0xF];
}
}
Home
Java Book
Runnable examples
Java Book
Runnable examples
Data Type Byte:
- Create Byte from byte value
- Convert byte to String using Byte.toString method
- Convert byte to String: Using concatenation with an empty String
- Convert byte to String: Creating a byte array and passing it to the String constructor
- Convert Byte array to Int
- Convert byte[] array to String
- Content byte[] array to hex string
- Convert data to byte array back and forth
- Min and Max values of byte
- Convert Byte to primitive data types
- Convert a byte to it's hexadecimal equivalent
- Convert byte Array To Hex String
- Shift byte left
- Shift byte right
- UnSign shift byte right