Java Hex Calculate toHexString(String input)

Here you can find the source of toHexString(String input)

Description

to Hex String

License

Open Source License

Declaration

private static String toHexString(String input) 

Method Source Code

//package com.java2s;
/**//from  w  ww  . j av  a 2  s.  c  o m
 * Confidential Information.
 * Copyright (C) 2007-2009 Eric Link, All rights reserved.
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 **/

public class Main {
    private static String toHexString(String input) {
        StringBuffer sb = new StringBuffer();
        byte[] bytes = input.getBytes();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(bytes[i]);
            if (hex.length() == 1) {
                sb.append("0");
            } else if (hex.length() > 2) {
                hex = hex.substring(hex.length() - 2, hex.length());
            }

            sb.append(hex);
            sb.append(" ");
        }
        return sb.toString();
    }
}

Related

  1. toHexString(long l)
  2. toHexString(long value, int digits)
  3. toHexString(long value, int digits)
  4. ToHexString(long[] data)
  5. toHexString(String data)
  6. toHexString(String s)
  7. toHexString(String s)
  8. toHexString(String s)
  9. toHexString(String str)