title: Converting IP address to hexadecimal dotted-quad format?
body: <p>I need help figuring out how to convert an ip address into a hexadecimal format in Java.</p>
  <pre><code>InetAddress ip = null;
  String hostname = null;
  
  Scanner console =  new Scanner(System.in);
  
  Scanner in= new Scanner(System.in);
  System.out.print(&quot;Enter Host name: &quot;);
  String host = console.nextLine();
  
  InetAddress inet = null;
  
  try {
    inet = InetAddress.getByName(host);
  } catch (UnknownHostException e) {
    e.printStackTrace();
  
  }
  
  //converting decimal dotted-quad format to binary
  byte[] bytes = InetAddress.getByName(host).getAddress();
  String binary = new BigInteger(1, bytes).toString(2);
  
  //converting decimal dotted-quad format to hexadecimal
  byte[] bytes1 = { 0x4D, 0x7D, 0x41, (byte)0xC9, (byte)0x1FA3 };
  
  
  //ip address of hostname
  String ipAdd= inet.getHostAddress();
  
  System.out.println(&quot;ip of Host: &quot; + ipAdd );
  System.out.println(&quot;Binary format: &quot; + binary );
  System.out.println(&quot;Hexadecimal dotted-quad format: &quot; + bytes1);
  </code></pre>
  <p>Here I have my java code where I have successfully grabbed an ip of a host and the ip in binary form. Here is an example of what my current program is running:</p>
  <pre><code>Enter Host name: www.harvard.edu
  ip of Host: 151.101.194.133    
  Binary format: 10010111011001011100001010000101    
  Hexadecimal dotted-quad format: [B@1ddc4ec2
  </code></pre>
  <p>how do I get my hexadecimal portion to be correct?</p>