title: How to convert Hexadecimal for Bluetooth LE write characteristic Swift 4
body: <p>What function do I need to pass 0x04 as a Data value to Peripheral characteristic in BLE? What int value can I pass to get a byte 0x04?</p>
  
  <pre><code>func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
  
      if let characteristics = service.characteristics {
  
          // I WANT TO WRITE 0x04 TO THE PERIPHERAL USING enableBytes below
          // enableByte MUST BE A SINGLE BYTE
  
          var enableValue:UInt8 = 4
          let enableByte = Data(bytes: &amp;enableValue, count: MemoryLayout&lt;UInt8&gt;.size)
          // This returns 04
          // print("enableByte is \(enableByte as NSData)")
  
          // writing to Characteristics
          for characteristic in characteristics {
  
              if characteristic.uuid == Device.OnOffUUID {
                  self.peripheral?.setNotifyValue(true, for: characteristic)
  
                  self.peripheral?.writeValue(enableByte, for: characteristic, type: .withResponse)
  
                  peripheral.readValue(for: characteristic) // this will call peripheral(_: didUpdateValueFor characteristic)
              }
          }
      }
  }
  </code></pre>