title: How convert string to byte[]?
body: <p>I have Arduino + Ethenet shield. I want to dynamically change the ip depending on that will come at the input com-port.</p>
  
  <p>The main problem is - input string has a String type, and <code>Ethernet.begin</code> method accepts a byte array. In general, I can not understand how to convert this string correctly. Tried to make a bicycle(crutch) by moving the string in the char array, and then in the byte array. Did not work out. How convert string to byte[]?</p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include &lt;Ethernet.h&gt;
  String readString;
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
  EthernetClient client;
  
  void initEthernetConfig(byte ip[])
  {
  
    Ethernet.begin(mac, ip);
    Serial.begin(9600); 
    Serial.println("Better client test 12/01/11"); // so I can keep track of what is loaded
    Serial.println("Send an e in serial monitor to test"); // what to do to test
  }
  
  void setup(){
    byte ip[] = { 10, 28, 33, 4 };
   // initEthernetConfig(ip);
  }
  
  void loop(){
    // check for serial input
  
     while (Serial.available()) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the String readString
      delay(2);  //slow looping to allow buffer to fill with next character
    }
  
    if (readString.length() &gt;0) {
    byte inArray[4];
    char * tokens;
      int i = 0;    
      tokens = strtok(readString, ".");
      while (tokens != NULL) {
          inArray[i] = atoi(tokens);
          tokens = strtok(NULL, ".");
          i++;
      }
    initEthernetConfig(inArray);
    }
  
  } 
  </code></pre>