Convert hex to bytes
968062
public static byte []toBytes(String hex)
  {
    if (hex == null)
      return null;
    
    int len = hex.length();

    byte []bytes = new byte[len / 2];

    int k = 0;
    for (int i = 0; i < len; i += 2) {
      int digit = 0;

      char ch = hex.charAt(i);

      if ('0' <= ch && ch <= '9')
        digit = ch - '0';
      else if ('a' <= ch && ch <= 'f')
        digit = ch - 'a' + 10;
      else if ('A' <= ch && ch <= 'F')
        digit = ch - 'A' + 10;

      ch = hex.charAt(i + 1);

      if ('0' <= ch && ch <= '9')
        digit = 16 * digit + ch - '0';
      else if ('a' <= ch && ch <= 'f')
        digit = 16 * digit + ch - 'a' + 10;
      else if ('A' <= ch && ch <= 'F')
        digit = 16 * digit + ch - 'A' + 10;

      bytes[k++] = (byte) digit;
    }

    return bytes;
  }
1042090
function _bnToBytes(b) {
  // prepend 0x00 if first byte >= 0x80
  var hex = b.toString(16);
  if(hex[0] >= '8') {
    hex = '00' + hex;
  }
  return forge.util.hexToBytes(hex);
}
187016
def to_hex(x):
    
    if isinstance(x, bytearray):
        x = bytes(x)
    elif isinstance(x, (list, tuple)):
        x = bytes(bytearray(x))
    if isinstance(x, basestring):
        return base64.b16encode(x).decode('ascii')
    else:
        raise ValueError('Unknown input argument type')
977873
def to_bytes(x):
    
    if isinstance(x, bytes):
        return x
    if isinstance(x, basestring):
        return x.encode('utf-8')
384604
def hexstr(x, onlyasc=0, onlyhex=0, color=False):
    """"""
    x = bytes_encode(x)
    _sane_func = sane_color if color else sane
    s = []
    if not onlyasc:
        s.append(" ".join("%02X" % orb(b) for b in x))
    if not onlyhex:
        s.append(_sane_func(x))
    return "  ".join(s)
1163616
def encode(hex)
      leading_zero_bytes = (hex.match(/^([0]+)/) ? $1 : '').size / 2
      int_val = hex.to_i(16)
      base58_val = ''
      while int_val > 0
        int_val, remainder = int_val.divmod(SIZE)
        base58_val = ALPHABET[remainder] + base58_val
      end
      ('1' * leading_zero_bytes) + base58_val
    end
158344
def hex(self):
        """"""
        addrstr = '000000'
        if self.addr is not None:
            addrstr = binascii.hexlify(self.addr).decode()
        return addrstr
826844
public static String hex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = HEXES_SMALL[v >>> 4];
            hexChars[j * 2 + 1] = HEXES_SMALL[v & 0x0F];
        }
        return new String(hexChars);
    }
231436
function encodeLengthHex(n) {
    if (n<=127) return toHex(n)
    else {
        var n_hex = toHex(n)
        var length_of_length_byte = 128 + n_hex.length/2 // 0x80+numbytes
        return toHex(length_of_length_byte)+n_hex
    }
}
83540
def _hex_to_octets(addr):
    '''
    
    '''
    return '{0}:{1}:{2}:{3}'.format(
        int(addr[6:8], 16),
        int(addr[4:6], 16),
        int(addr[2:4], 16),
        int(addr[0:2], 16),
    )
194299
public static String toHexString(byte b) {
    StringBuffer sb = new StringBuffer(4);
    sb.append("0x").append(HEX_CHARS[0x0F & (b >> 4)])
        .append(HEX_CHARS[b & 0x0F]);
    return sb.toString();
  }
327402
function bytesToHex(arr) {
    if (arr instanceof ArrayBuffer) {
        arr = new Uint8Array(arr);
    }
    var str = '';
    for (var i = 0; i < arr.length; i++) {
        var byte = arr[i].toString(16);
        if (byte.length === 1) {
            str += '0';
        }
        str += byte;
    }
    return str;
}
924131
private static String byte2hex(byte b[]) {
		StringBuilder sb = new StringBuilder();
		for (int n = 0; n < b.length; n++) {
			String stmp = Integer.toHexString(b[n] & 0xff);
			if (stmp.length() == 1) {
				// hs = hs + "0" + stmp;
				sb.append("0");
			}
			sb.append(stmp);
			// else {
			// // hs = hs + stmp;
			// }
		}

		return sb.toString().toUpperCase();
	}
930419
def to_bytes(s, encoding="utf-8"):
    
    if isinstance(s, six.binary_type):
        return s
    else:
        return six.text_type(s).encode(encoding)
199855
def to_bytes(self):
        """"""
        s = identity_to_string(self.identity_dict)
        return unidecode.unidecode(s).encode('ascii')
1047932
public static byte[] hexToBytes(char[] hex)
    {
        int length = hex.length / 2;
        byte[] raw = new byte[length];
        for (int i = 0; i < length; i++)
        {
            int high = Character.digit(hex[i * 2], 16);
            int low = Character.digit(hex[i * 2 + 1], 16);
            int value = (high << 4) | low;
            if (value > 127)
            {
                value -= 256;
            }
            raw[i] = (byte) value;
        }
        return raw;
    }
953114
function toUtf8(hex) {
  const bufferValue = new Buffer(padToEven(stripHexPrefix(hex).replace(/^0+|0+$/g, '')), 'hex');

  return bufferValue.toString('utf8');
}