title: String to hexadecimal
body: <p>I need a method to convert a string "IP:PORT" into a byte array. I know how to format manually, but I need a way to do it automatically.</p>
  
  <p>Example IP:</p>
  
  <blockquote>
    <p>77.125.65.201:8099</p>
  </blockquote>
  
  <p>I just can't use "".getBytes(); because I need the following format (without dot and colon):</p>
  
  <blockquote>
    <p>[#1 octet ip] [#2 octet ip] [#3 octet ip] [#4 octet ip] [#1 2 octet port]</p>
  </blockquote>
  
  <p>For a better understanding:</p>
  
  <blockquote>
    <p>77 125 65 201 8099</p>
  </blockquote>
  
  <p>In Java manually I can set it:</p>
  
  <pre><code>byte[] testIP = { 0x4D, 0x7D, 0x41, (byte)0xC9, (byte)0x1FA3 };
  </code></pre>
  
  <p>I need to find a method that will return a byte array in the correct format, casting to byte when it's necessary (because of Java signed bytes).</p>
  
  <p>This is what have I made but it's not working:</p>
  
  <pre><code>private void parseIp(String fullData){
     String[] data = fullData.split(":"); // 8099
     String[] ip = data[0].split("\\."); // 77 | 125 | 65 | 201
  
     for(int i = 0; i &lt; 4; i++){
        System.out.println("---&gt; " + toHex(ip[i]));
     }
  }
  
  private String toHex(String data){
     return Integer.toHexString(Integer.parseInt(data, 16));
  }
  </code></pre>