Is there any way of converting from byte[] to hex representation? I've search everywhere but i can't find anything! Can someone please help me?
            Asked
            
        
        
            Active
            
        
            Viewed 299 times
        
    -1
            
            
        - 
                    And what do you call "hex representation" exactly? – fge Apr 21 '14 at 14:41
- 
                    @ElliottFrisch Did you test those methods? Pretty sure `if (len < 0) {` should be `if (len > 0) {`. BTW, I think some of [these answers](http://stackoverflow.com/questions/9655181/) are by far more efficient. – Tobias Apr 21 '14 at 14:47
1 Answers
0
            try this:
private static String   digits = "0123456789abcdef";
   public static String toHex(byte[] data){
    StringBuffer    buf = new StringBuffer();
    for (int i = 0; i != data.length; i++)
    {
        int v = data[i] & 0xff;
        buf.append(digits.charAt(v >> 4));
        buf.append(digits.charAt(v & 0xf));
    }
    return buf.toString();
}
 
    
    
        Snox
        
- 580
- 1
- 10
- 24
