title: Using extended Hex Codes in Xcode
body: <p>I am all very new to this and am trying to use extended hex codes (past the ascii characters of 127) that are generated by converting a decimal number to float number that is then being sent via a post command to a device to change a set point.</p>
  
  <p>I am creating the hex codes by simply doing this,</p>
  
  <pre><code>- (void)dec2float:(id)sender
  {
      NSString *dec = setPoint.text;
      float flt = [dec floatValue];
      unsigned char *bytes = (unsigned char *)&amp;flt;
      sPoint01 = [NSString stringWithFormat:@"%x", bytes[0]];
      sPoint02 = [NSString stringWithFormat:@"%x", bytes[1]];
      sPoint03 = [NSString stringWithFormat:@"%x", bytes[2]];
      sPoint04 = [NSString stringWithFormat:@"%x", bytes[3]];
  }
  </code></pre>
  
  <p>If the setPoint.text value is for example 23 this will make </p>
  
  <pre><code>sPoint01 = 00
  sPoint02 = 00
  sPoint03 = b8
  sPoint01 = 41
  </code></pre>
  
  <p>These values then have to be sent to the device as a hexadecimal string which is being joined together as so,</p>
  
  <pre><code>NSString *post = [NSString stringWithFormat:@"\\x%@\\x%@\\x%@\\x%@",sPoint01, sPoint02, sPoint03, sPoint04];
  </code></pre>
  
  <p>but instead of "0000b841" being sent I am getting "00005c78 62385c78 3431". I am assuming this is because Xcode won't allow any hex code past 127 as if I try and type it in as so </p>
  
  <pre><code>@"\xb8"
  </code></pre>
  
  <p>Xcode tells me that the "Input conversion has stopped due to an input byte that does not belong to the input codeset UTF-8".</p>
  
  <p>Am I going about this in the right way or have I managed to wander a long way down the wrong road?</p>
  
  <p>Any help would be much appreciated and any advice welcomed.</p>
  
  <p>Thank you in advance</p>
  
  <p>Edit:</p>
  
  <p>Hi,
  Thanks for the reply this is the command that I am using to send the data to the controller hopefully it will be of help,</p>
  
  <pre><code>- (void)setACStatus:(id)sender
  {    
  NSString *post = [NSString stringWithFormat:@"\x38\x00\x00\x00\x76\x11\x01\x00%@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00%@\x00%@%@\x00\x10\x00\x10%@%@%@%@%@\x00\x00\x00",
                        unitNumberString, onOffString, modeString, modeString2, sPoint01, sPoint02, sPoint03, sPoint04, 
                        fanSpeedString];
  
       postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];    
  
      NSString *postLength = [NSString stringWithFormat:@”%d”, [postData count];
  
      NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  
      [request setURL:[NSURL URLWithString:@”http://10.38.140.9/cmd/”]];//&lt;-- Controller address.
      [request setHTTPMethod:@"POST"];
      [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
      [request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
      [request setHTTPBody:postData];
  
      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  
      if( theConnection )
      {
          webData = [NSMutableData data];
      }
      else
      {
          NSLog (@"The Connection is NULL");
      }
  
      temp.text = [NSString stringWithFormat:@"%@",postData];
  }
  </code></pre>
  
  <p>Thankyou.</p>